I have a folder structure like this
--Page
-group.vue
--Services
-groupMixin.ts
script of group.vue
<script lang="ts">
import { Vue, Component, Mixins } from 'vue-property-decorator'
import { GroupMixin } from '../../services/groupMixin';
@Component
export default class Group extends Mixins(GroupMixin) {
created () {
console.log(this.test)
}
}
</script>
code of groupMixin.ts
import { Vue } from 'vue-property-decorator'
//creating mixins.
export class GroupMixin extends Vue {
test: string = 'sss'
}
I am facing two problems here.
First, to import a ts file i used ../../, is there any way to use ./ or @/. Without using lang="ts", i can import a js file like this @/services/...
Second, not able to access the varaible test which i declared in groupmixin.ts.
Please try to do the following to make your mixin to work:
group.vue
groupMixin.ts
There is a reason that I am using importing
Vueusingimport Vue from 'vue';, it is mainly because some IDE's are highlighting Vue functions like$emitwhen it is imported fromvue-class-component.As for import ts files if you are not using
vue-cliyou'll need to setup webpack's resolve alias and also in yourtsconfig.jsonand possibly will need to use tsconfig-paths