1
我是使用Vue的新手。我正在试图围绕插件。使用Vue插件
组件:Rest.vue
...
export default {
name: 'rest',
data() {
return {
}
},
methods: {
gplFetch: function(query){
...
return ...;
}
}
}
...
插件:全局插件
import Rest from ‘@/components/Rest.vue’
export default {
install(Vue, options) {
Vue.component(Rest.name, Rest)
Vue.mixin({
created() {
console.log('rest created');
}
})
Vue.prototype.$gplFetch = function(query){
return <Access Rest component>.gplFetch(query);
}
}
}
用什么,我被困在使用组件及其方法,我添加到我的插件main.js
import GlobalPlugin from '@/plugins/global-plugin.js'
Vue.use(GlobalPlugin);
却困在什么是如何在上面的代码中访问gplFetch:
return <Access Rest component>.gplFetch(query);
非常感谢。你提供了一个解决方案,但你也提供了一个我决定采用的更好的解决方案。你太棒了 :) – adviner