vue开发自己的插件引入问题

1.这是我写的插件

var MyPlugin = {}
MyPlugin.install = function (Vue, options) {
  var utils = {
    get: function (url, parms) {
      Vue.$http.jsonp(url)
    }
  };
  Vue.prototype.myUtils = utils
}
module.exports = MyPlugin

2.这是main.js中的引入顺序

import Vue from 'vue'
import App from './App'
import router from './router'
import VueResource from 'vue-resource'
import myPlugin from '../static/utils.js'
Vue.config.productionTip = false
Vue.use(VueResource)
Vue.use(myPlugin)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App },
  data: {
    eventHub: new Vue()
  }
})

3.调用时候的代码

methods: {
        postmsg () {
          this.myUtils.get('http://localhost:3000/showstep')
              .then(response => {
                console.log(typeof response.data)
                this.newmsg = response.data[0].stepname
              })
          this.$root.eventHub.$emit('add', '111')
        }
      }

4.浏览器报错如下:

clipboard.png

我的插件是在vue-resource和Vue之后引入的啊,为什么还是找不到Vue这个实例呢?

阅读 2.5k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题