单独只用vue2的双向绑定ajax请求多次vue里的data不刷新

图片描述

        type:"get",
        url:urlIp + "getFooter.jsonp",
        dataType:"jsonp",
        jsonp:"callback",
        success:function(data){
            if (data.status == 1) {
                // dataList = data ;
                //页脚数据展示
                var app = data.result.APP,
                    m_web = data.result.M站,
                    amount = ((data.result.amount)/1000).toFixed(2),
                    other = data.result.其它,
                    times = data.result.time;
                var footer = new Vue({
                    el: '.footer-r',
                    data: {
                        time:times,
                        amount:amount,
                        APP: nub(app),
                        其它:nub(other),
                        M站:nub(m_web),

                    },

                });
            }
            **

我一分钟请求一次 但突然发现Vue内的data不变,用的vue2

**

阅读 4.1k
2 个回答

获取数据写方法里,请求写在生命周期事件里。试试

    //家具
    var rosewoodFurniture = new Vue({
        el: '#rosewoodFurniture',
        data: {
            id: '',
            Title: '', Introduction: '', Craftwork: '', Specifications: '', Culture: '',
            Material: '', ProductionPlace: '', TakePlace: '',
        },
        methods: {
            //加载数据
            Load: function (data) {
                this.Title = data.Title;
                this.Introduction = data.Introduction;
                this.Craftwork = data.Craftwork;
                this.Specifications = data.Specifications;
                this.Culture = data.Culture;
                this.Material = data.Material;
                this.ProductionPlace = data.ProductionPlace;
                this.TakePlace = data.TakePlace;
                // 触发组件 A 中的事件
                bus.$emit('setdetail', data.Details)
                // 触发组件 A 中的事件
                bus.$emit('setimages', data.Images)
            },
            //获取数据
            Get: function () {
                Api.Show.RosewoodFurniture.Single(this.Load,{ id: this.id });
            },
        },
        mounted: function () {
            this.id = $.GetUrlParam('Id');
            this.Get();
        }
    })

用watch试试

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