我main.js
在 Vue.js 项目的 中声明了一个全局变量。
Vue.prototype.$API = "myapihere"
Run Code Online (Sandbox Code Playgroud)
我想从任何地方使用它。并且通过使用它可以正常工作this.$API
。
但是在 Vuex 中它不起作用。
console.log(this.$API);
Run Code Online (Sandbox Code Playgroud)
这里this.$API
是undefined。
我如何$API
在 Vuex 中使用我的。
根据本地 Vue-storefront 的安装,我有一些疑问。\n我使用的是 Mac OS 10.13.4 和节点版本 8.11.5,npm 版本 5.6\n但是在构建 storefront npm 时,它返回一个错误。
\n\n [Error: Can't build storefront npm. \xe2\x94\x82\n\xe2\x94\x82 at Promise (/Volumes/Works/web/vue/vuestorefront/vue-storefront/core/scripts/installer.js:412:16) \xe2\x94\x82\n\xe2\x94\x82 at new Promise (<anonymous>) \xe2\x94\x82\n\xe2\x94\x82 at Storefront.npmBuild (/Volumes/Works/web/vue/vuestorefront/vue-storefront/core/scripts/installer.js:408:12) \xe2\x94\x82\n\xe2\x94\x82 at <anonymous> \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 Please check log file for details: /Volumes/Works/web/vue/vuestorefront/vue-storefront/var/log/install.log][1] \n
Run Code Online (Sandbox Code Playgroud)\n\n为什么会出现这种情况?
\n目前我在Product.vue
文件中有以下手表
watch: {
isOnline: {
async handler (isOnline) {
if (isOnline) {
const maxQuantity = await this.getQuantity();
this.maxQuantity = maxQuantity;
}
}
},
isMicrocartOpen: {
async handler (isOpen) {
if (isOpen) {
const maxQuantity = await this.getQuantity();
this.maxQuantity = maxQuantity;
}
},
immediate: true
},
isSample (curr, old) {
if (curr !== old) {
if (!curr) {
console.log('send the updateCall', curr);
// this.updateProductQty(this.product.qty);
pullCartSync(this);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我在控制台中收到以下错误(Vue Warn)
[Vue 警告]:方法“watch”在组件定义中具有“object”类型。您是否正确引用了该函数?
我不确定为什么我会收到这个错误,因为我使用的语法似乎是正确的,它甚至可以正常运行。
任何建议为什么它在错误控制台中发出此警告?
更新:
我在 vue 页面中使用手表的位置。