VUE 拿到了数据以后 怎么向data中赋值

问题描述

如图就死活拿不到数据了,不知道怎么回事求大神解救一下

问题出现的环境背景及自己尝试过哪些方法

clipboard.png

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
new Vue({

        el: '#a-weather-waring',
        data: {
            weatherWaring:null,
            v_time_from2: null,
            v_time_toto2: null
        },
        methods: {
            Get_YJweather: function() {
                this.v_time_from2 = this.$refs.v_time_from.value;
                this.v_time_toto2 = this.$refs.v_time_toto.value;
                mui.ajax('http://lbzhywpt.portdalian.com:999/WeatherHandler.ashx?method=Get_YJweather', {
                    data: {
                        timefrom: this.v_time_from2,
                        timeto: this.v_time_toto2
                    },
                    dataType: 'json', //服务器返回json格式数据
                    type: 'post', //HTTP请求类型
                    timeout: 10000, //超时时间设置为10秒;
                    success: function(result) {
                        console.log(result);
                        this.weatherWaring = result;
                        console.log(weatherWaring);
                    },
                    error: function(xhr, type, errorThrown) {}
                });
            },
        }
    });

你期待的结果是什么?实际看到的错误信息又是什么?

阅读 7.4k
1 个回答

this.weatherWaring = result;
你这里的this指向的是mui所以赋值失败;

methods: {
   Get_YJweather: function() {
        var _this = this;
        this.v_time_from2 = this.$refs.v_time_from.value;
        this.v_time_toto2 = this.$refs.v_time_toto.value;
        mui.ajax('http://lbzhywpt.portdalian.com:999/WeatherHandler.ashx?            
          method=Get_YJweather', {
            data: {
                timefrom: this.v_time_from2,
                timeto: this.v_time_toto2
            },
            dataType: 'json', //服务器返回json格式数据
            type: 'post', //HTTP请求类型
            timeout: 10000, //超时时间设置为10秒;
            success: function(result) {
                console.log(result);
                _this .weatherWaring = result;
                console.log(weatherWaring);
            },
            error: function(xhr, type, errorThrown) {}
        });
     }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题