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

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

问题描述

感谢您阅读我的问题.

我已经阅读了我的问题

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

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

But my system no read Vue var :(

我有一个调用 app.vue 的 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

你有解决办法吗?

我的 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 的属性“帖子"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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