res.data.amount一直返回不了价格是怎么回事?
来源:7-7 购买详情页 - 总价计算(2)

野火燎原
2017-04-30
代码是直接复制过来的,但是页面载入时,db.json 的字段会直接变成下面这样,就算一开始在db.json加入了价格,页面重载时还会变成下面这样,不能获取价格
db.json
"getPrice": {"amount": 123}
页面载入时变为
"getPrice": {
"buyNum": 1,
"buyType": 0,
"period": 0,
"version": "0"
},
没有获取"getPrice": {"amount": 123},而是修改了"getPrice"的内容。
analysis.vue
onParamChange (attr, val) {
this[attr] = val
this.getPrice()
},
getPrice () {
let buyVersionsArray = _.map(this.versions, (item) => {
return item.value
})
let reqParams = {
buyNum: this.buyNum,
buyType: this.buyType.value,
period: this.period.value,
version: buyVersionsArray.join(',')
}
this.$http.post('/api/getPrice', reqParams)
.then((res) => {
this.price = res.data.amount
})
}
mounted () {
this.buyNum = 1
this.buyType = this.buyTypes[0]
this.versions = [this.versionList[0]]
this.period = this.periodList[0]
this.getPrice()
}
2回答
-
页面重载后还会变成哪样?db.json里是假数据,页面里改动的只是浏览器里的js数据,改不了db.json里的数据
062017-05-03 -
fishenal
2017-05-01
你的发送请求代码是什么样的?是不是用了 json-server? 用json-server的话 post请求会改变db.json里的值
012017-05-02
相似问题