exception: TypeError: Cannot read property '_modulesNamespaceMap' of undefined at getModuleByNamespac

用 Vue.extend 创造的组件构造器和组件,默认是不集成 store 和 router 的。

比如 main.js 中的这个,其实是挂载在根组件 vm 中。并不是注入到全局 Vue 中。所以你用 Vue.extend 构造的理所当然没有了。但是,你用 Vue.mixin 注入的就是有的。

const vm = new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')

所以,如果你 extend 创造的组件,需要重新集成。

import fuck from './fuck.vue'

// Vue组件构造器
const Fuck = Vue.extend(fuck)

// 实例化组件
const instance = new Fuck({ /* ... */ })

// 集成 store
instance.$store = this.$store

// 集成 router
instance.$router = this.$router

// 挂载
instance.$mount('#app')

猜你喜欢

转载自www.cnblogs.com/CyLee/p/11865591.html