钩子中读取数据报错post undefined,也引用了vue-resource,这是为什么呀

以下是我的代码,

mounted() {
    this.initList()
},
methods:{
    initList: function(){
        this.$http.post('/api/user/SelectTitle',{},{}).then((response) => {
            this.service_show_list = response.body;
        })
    }
},

但是会报错显示Error in mounted hook: "TypeError: Cannot read property 'post' of undefined",但是如果通过按钮直接调用initList函数就是没有问题的,麻烦问一下您知道这是怎么回事儿吗~我在main.js中引用了vue-resource的

import VueResource from 'vue-resource'

Vue.config.productionTip = false

new Vue({
el: '#app',
template: '<App/>',
components: { App }
})

Vue.use(VueResource)
阅读 4.6k
1 个回答
  mounted:function(){
    this.initList();
    }

另外vue官方建议不要使用vue-resource了,用axios代替。

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