无法读取未定义vue的属性“ post” [英] Cannot read property 'post' of undefined vue

查看:817
本文介绍了无法读取未定义vue的属性“ post”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您阅读我的问题。

我已了解我的问题

VUE JS 2 + WEBPACK无法读取未定义的属性 get VUE资源

但是我的系统没有读取Vue var:(

But my system no read Vue var :(

我有一个vue组件调用app.vue,我需要使用vue-resource从我的帖子中获取数据,但是很多时候的错误是:

I have a vue component calls app.vue and i need to use vue-resource to get data from my post. But the error a lot times is:

TypeError: Cannot read property 'post' of undefined
at VueComponent.loadingProcess

Do读取未定义
的属性 post有解决的想法吗?

Do u have ideas to solve it?

我的app.vue

<script>
    var Vue = require('vue');
    //Vue.use(require('vue-resource'));
    //Vue.use();

    export default {
          data () {
                return {
                    msg: 'Hello from vue-loader! nice!',
                    user: {}
            }
    },
    mounted: function () {
        this.loadingProcess();
    },
    methods: {
        loadingProcess: function () {

            var urlPost;
            var answQSend = {...};
            var that = this;

            var jsonSend = {
                "form_data": answQSend,
                "prod_id": 3
            };

            Vue.$http.post(urlPost, jsonSend, {
                "headers": {
                    "content-type": "application/json"
                }
            })
            .then(function(response) {

            })
            ...

谢谢!

推荐答案

首先,感谢@Bert谁有耐心并帮助我找到解决方法

First of all, thanks to @Bert who was patient and helped me find the solution

在main.js中,我更改了这一行

In my main.js, i changed this line

var VueResource = require('vue-resource');

用于

import VueResource from "vue-resource"

并使用

Vue.use(VueResource);

然后,在我的应用程序vue组件中,我更改了

Then, in my app vue component i changed

Vue.http.post

对于

this.$http.post

这样我们就可以纠正错误!

That way we fixed the error!

这篇关于无法读取未定义vue的属性“ post”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆