### v-model与:v-model
### 在 uniapp开发小程序中动态添加form表单项的踩坑日记
代码如下:
//原始项
<view class="center_box" v-for="(item,index) in arr" :key="index">
<view class="top">
<view class="top_left">
<input type="text" value="" v-model="item.person" :placeholder=" '请选择人员'+(index+1) "
placeholder-style="color:black;" />
</view>
<view class="top_right">
<input type="text" value="" v-model="item.document" placeholder="请选择工作流程"
placeholder-style="color:black;" />
</view>
</view>
<view class="bottom">
<input type="text" value="" v-model="item.plan" placeholder="填写明天工作计划"
placeholder-style="color:black;" />
</view>
</view>
//添加项
<view class="add_item">
<view class="top">
<view class="top_left">
<input type="text" value="+" v-model="datepicker" placeholder="+"
placeholder-style="color:black;" @click="submit_m" />
</view>
<view class="top_right">
<input type="text" value="" v-model="datepicker" />
</view>
</view>
</view>
//提交打印结果
<view @click="submit" class="submitbtn"><label>发布任务</label></view>
export default {
data() {
return {
arr: [{
person: '',
document: '',
plan: ''
}],
obj: {
person: '',
document: '',
plan: ''
}
}
},
methods: {
//添加项
submit_m() {
this.arr.push(this.obj)
this.obj = {}
},
submit() {
console.log(this.arr)
}
}
}
notice:
刚开始用:v-model拿到的值一直为空串,改成v-model以后才确定是自己想要的值。
从动态添加表单项看出来v-model的双向绑定与:v-model的单项数据绑定,前车之鉴!!
喜欢苏轼的 不思量,自难忘,无处话凄凉。
共勉!