I am currently developing a Vue application using TypeScript. I have created a mixin (which can be found in global.mixin.js
) and registered it using Vue.mixin()
(as shown in main.ts
).
Content of global.mixin.js:
import { mathHttp, engHttp } from '@/common/js/http'
export default {
methods: {
wechatShare(config) {
config.imgUrl = config.imgUrl
mathHttp.get('/wechat/config', {
url: encodeURIComponent(window.location.href),
}).then((data) => {
wx.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.noncestr,
signature: data.signature,
jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'],
})
})
wx.ready(() => {
wx.updateAppMessageShareData(config)
wx.updateTimelineShareData(config)
})
},
},
}
Contents of main.ts:
I added the global mixin to my app using Vue.mixin()
:
import globalMixins from './mixins/global.mixin'
Vue.mixin(globalMixins)
However, when I attempt to access the mixin method within a Vue component, I encounter an error message:
property wechatShare doesn't exist on type Test.vue
Content of Test.vue:
<script lang='ts'>
import { Component, Prop, Vue } from 'vue-property-decorator'
@Component({ components: { } })
export default class Test extends Vue {
created() {
this.setWeChatShare()
}
setWeChatShare() {
this.wechatShare
}
}
</script>
How would you recommend resolving this issue?