Vue学习过程中遇到的问题记录
1、输入校验
1)filter
只能在{{}} 、v-bind中使用,不能用于v-model
2)change
v-model不能用filter,可以在change事件中进行判断
3)rules
如果使用了ElementUI,它提供了rules来添加表单校验
https://element.eleme.cn/#/zh-CN/component/form#form-item-attributes
更多校验规则:https://github.com/yiminghe/async-validator
添加rules的方式:
todo
https://segmentfault.com/a/1190000020410128
2、动态组件
想实现动态切换页签可以使用动态组件
想要保留页签状态可以使用keep-alive
<keep-alive>
<component :is='currentTabComponent'><component>
</keep-alive>
vue的[动态组件](https://cn.vuejs.org/v2/guide/components.html#%E5%8A%A8%E6%80%81%E7%BB%84%E4%BB%B6)
3、watch 深度监听
https://www.cnblogs.com/amujoe/p/11429691.html
firstName: {
handler(newName, oldName) {
this.fullName = newName + ' ' + this.lastName;
},
// 代表在wacth里声明了firstName这个方法之后立即先去执行handler方法
immediate: true,
deep:true
}
4、在使用rules校验el-form时,this.$ref取不到值
https://cn.vuejs.org/v2/guide/components-edge-cases.html#%E8%AE%BF%E9%97%AE%E5%AD%90%E7%BB%84%E4%BB%B6%E5%AE%9E%E4%BE%8B%E6%88%96%E5%AD%90%E5%85%83%E7%B4%A0
5、vue中v-model v-bind:value的区别
https://www.cnblogs.com/liubingyjui/p/12851593.html
https://blog.csdn.net/chiuwingyan/article/details/78163039
https://blog.csdn.net/wildg00se/article/details/100833229
总结
v-model:是value和oninput事件的结合,可以动态地对value进行改变,就是如果value被改变了,可以很快地反映到对应的组件当中,改变该组件的value。
是双向绑定,即表单可以拿到vue中的数据,表单中的数据也可以传到vue中
v-bind:value: 只能是表单拿到vue的数据,vue无法拿到表单的数据
6、Vue.component VS Vue.extend TODO
https://segmentfault.com/q/1010000007312426