代码是直接复制过来的,但是页面载入时,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()
}