v-model 指令在表单控件元素上创建双向数据绑定,下面一一进行示例解释。
1、v-model 双向绑定文本
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.js">输出结果:
2、v-model 双向绑定多行文本,与上面的例子相似。
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.js">输出结果:
3、v-model 绑定复选框
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.js">输出结果:选中为true 不选中则为false
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.js">输出结果:
4、v-model 绑定单选按钮
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.js">输出结果:
5、v-model 绑定下拉列表
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.js">输出结果:
多选列表
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.js">输出结果:
6、动态选项,用 v-for 渲染: