common.js
function add(a,b) => {
return a+b
}
const sub = (a,b) => {
return a-b
}
module.exports = {
add,
sub
}
main.js
```typescript
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
import common from './common/common.js';
Vue.prototype.$common = common;
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import {
createSSRApp
} from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif
index.vue
export default {
data() {
return {
}
},
onLoad(){
console.log(this.$common.add(1,1))
},
methods: {
}
}
console.log(this.$common.add(1,1))
调用时报错
[TypeError] {message: "Cannot read property 'add' of undefined"}
怎么解决?求解。