new Vue({
el: '.wrap',
data: {
addressList: [],
productList: [],
sendMessage: ''
},
mounted: function() {
this.$nextTick(function() {
this.getAddressList();
this.getProductList();
this.getSendMessage();
});
},
methods: {
getAddressList: function() {
this.$http.get('data/address.json', {}).then(res => {
this.addressList = res.data.result;
});
},
getProductList: function() {
this.$http.get('data/cart.json', {}).then(res => {
this.productList = res.data.result.productList;
});
},
getSendMessage: function() {
var _this = this;
this.addressList.forEach(function(item, index) {
if (item.isDefault) {
_this.sendMessage = item.streetName + item.userName + item.postCode;
}
});
}
}
});
其他地方都正常运行了
this.addressList返回的是json数据
streetName userName postCode 都在json里有
大概是这样的json
在html里 用 {{ sendMessage }} 引用数据了
sendMessage并没有改变值
是不是不能这么写函数?
相关分类