$router redefine 和 Vue.use(Vuex) 应该只被调用一次
$router redefine and Vue.use(Vuex) should be called only once
我的项目由 webpack 模板创建!!;
npm 运行 构建
网上还可以,但是vendor.js太大了!
修改 webpack 配置 webpack.prod.conf.js
添加:
js
externals: {
'vue': 'Vue',
'vee-router': 'VueRouter',
'vuex': 'Vuex',
},
我把vue
,vue-router
,vuex
分开了,用CDN收录!喜欢:
html
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
<script src="https://unpkg.com/vue@2.3.4/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@2.3.1/dist/vue-router.js"></script>
<script src="https://unpkg.com/vuex@2.3.1"></script>
</body>
但是当我上传文件到线路时,出现了一些问题,例如:
vuex@2.3.1:667 [vuex] already installed. Vue.use(Vuex) should be
called only once.
vendor.js:24 Uncaught TypeError: Cannot redefine property: $router
at Function.defineProperty ()
at Function.v [as install] (vendor.js:24)
at Function.Vue.use (vue.js:4110)
at Object. (vendor.js:24)
at r (manifest.js:1)
at Object. (app.js:1)
at r (manifest.js:1)
at Object. (app.js:1)
at r (manifest.js:1)
at Object. (app.js:1)
有人可以帮助我吗?
如果您通过 CDN 加载 Vue 和 Vuex - 您不需要使用 Vue.use (...)
我的项目由 webpack 模板创建!!;
npm 运行 构建
网上还可以,但是vendor.js太大了!
修改 webpack 配置 webpack.prod.conf.js
添加:
js
externals: {
'vue': 'Vue',
'vee-router': 'VueRouter',
'vuex': 'Vuex',
},
我把vue
,vue-router
,vuex
分开了,用CDN收录!喜欢:
html
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
<script src="https://unpkg.com/vue@2.3.4/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@2.3.1/dist/vue-router.js"></script>
<script src="https://unpkg.com/vuex@2.3.1"></script>
</body>
但是当我上传文件到线路时,出现了一些问题,例如:
vuex@2.3.1:667 [vuex] already installed. Vue.use(Vuex) should be called only once. vendor.js:24 Uncaught TypeError: Cannot redefine property: $router at Function.defineProperty () at Function.v [as install] (vendor.js:24) at Function.Vue.use (vue.js:4110) at Object. (vendor.js:24) at r (manifest.js:1) at Object. (app.js:1) at r (manifest.js:1) at Object. (app.js:1) at r (manifest.js:1) at Object. (app.js:1)
有人可以帮助我吗?
如果您通过 CDN 加载 Vue 和 Vuex - 您不需要使用 Vue.use (...)