【发布时间】:2017-10-18 10:38:01
【问题描述】:
这是我现在的代码:https://jsfiddle.net/5phq111c/5/
HTML部分
<tbody v-for="row in rows" :key="row.product_id">
<tr>
<td>
<select @change="selected" v-model="row.product_id" class="form-control" name="product_id" id="product_id">
<option value="">Select Product</option>
<option v-for="item in items" :value="item.id" v-text="item.product_name"></option>
</select>
</td>
<td>
<textarea type="text" v-model="product.product_details" name="product_details" id="product_details" class="form-control" rows="1" placeholder="Product Details">
</textarea>
</td>
<td>
<input v-model.number="product.product_sellPrice" type="number" step="any" class="form-control" name="rate" id="rate" placeholder="Rate">
</td>
</tr>
</tbody>
Vue JS 部分
export default {
data() {
return {
rows: [{
product_id: '',
product_details: '',
product_sellPrice: '',
}],
}
},
methods: {
addrow: function (event) {
event.preventDefault();
this.rows.push({
product_id: '',
product_details: '',
product_sellPrice: '',
});
},
selected(e) {
var id = this.row.product_id;
console.log(id);
axios.get('/estimate/product/' + id)
.then((response)=>{
this.product = '';
this.product = response.data;
})
.catch((error) => {
console.log(error);
});
}
}
我想获取选中的product_id,并发送一个axios请求来获取选中的产品的值。我已将 product_id 与该行绑定。我在行对象中获取选定的值,但是当我通过 row.product_id 发送请求时,我收到错误无法读取未定义的属性“product_id”。问题出在哪里?
【问题讨论】: