[Vue] 13.Vue中的双向绑定(1) ----基本用法

news/2024/7/10 2:00:47 标签: 前端, javascript, vue

一、双向绑定

  1. 表单元素的双向绑定:v-model
  1. input
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>13</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="root"></div>
    <script>
        const app = Vue.createApp({
            data() {
                return {
                    message: 'hello'
                }
            },
            template: `
                <div>
                    {{message}}
                    <input v-model="message"/>
                </div>
                `,
        });
        const vm = app.mount('#root')
    </script> 
</body>
</html>

2 ) textarea:

<script>
        const app = Vue.createApp({
            data() {
                return {
                    message: 'hello'
                }
            },
            template: `
                <div>
                    {{message}}
                    <textarea v-model="message" />
                </div>
                `,
        });
        const vm = app.mount('#root')
    </script>

3 )一个checkbox:

<script>
        const app = Vue.createApp({
            data() {
                return {
                    message: false
                }
            },
            template: `
                <div>
                    {{message}}
                    <input type="checkbox" v-model="message"/>
                </div>
                `,
        });
        const vm = app.mount('#root')
    </script> 

4 ) 多个checkbox

<script>
        const app = Vue.createApp({
            data() {
                return {
                    message: []
                }
            },
            template: `
                <div>
                    {{message}}
                    jack <input type="checkbox" v-model="message" value="jack" />
                    jason <input type="checkbox" v-model="message" value: dell />
                    join <input type="checkbox" v-model="message" value="lee" />
                </div>
                `,
        });
        const vm = app.mount('#root')
    </script> 

在这里插入图片描述

5 ) radio:

<script>
        const app = Vue.createApp({
            data() {
                return {
                    message: ''
                }
            },
            template: `
                <div>
                    {{message}}
                    jack <input type="radio" v-model="message" value="jack" />
                    jason <input type="radio" v-model="message" value="jason" />
                    join <input type="radio" v-model="message" value="join" />
                </div>
                `,
        });
        const vm = app.mount('#root')
    </script>

在这里插入图片描述
6 ) select

<script>
        const app = Vue.createApp({
            data() {
                return {
                    message: ''
                }
            },
            template: `
                <div>
                    {{message}}
                    <select v-model="message">
                        <option>A</option>
                        <option>B</option>
                        <option>C</option>
                    </select>
                </div>
                `,
        });
        const vm = app.mount('#root')
    </script>

在这里插入图片描述

7 ) select 多选

<script>
        const app = Vue.createApp({
            data() {
                return {
                    message: [],
                    options: [{
                        text: 'A', value: 'A'
                    },
                    {text: 'B', value: 'B'},
                    {text: 'C', value: 'C'}
                ]
                }
            },
            template: `
                <div>
                    {{message}}
                    <select v-model="message" multiple>
                       <option v-for="item in options" :value="item.value">{{item.text}}</option>
                    </select>
                </div>
                `,
        });
        const vm = app.mount('#root')
    </script>

http://www.niftyadmin.cn/n/1440477.html

相关文章

用JSP创建WAP应用(转)

使用ASP或者JSP来创建动态WML内容&#xff0c;是非常容易的。唯一要注意的就是配置服务器使它的脚本输出类型为"text/vnd.wap.wml"&#xff0c;或者在脚本中直接设置输出类型。下面是一个用JSP输出动态WML内容的例子&#xff1a;<?xml version"1.0"?&…

不要忽视代码审查的重要性

这是一篇译文&#xff0c;觉得它很不错就把它翻译了一下。原文名为 8 Tips for Great Code Reviews&#xff0c;这篇文章不管是对提升个人编程素养&#xff0c;还是协调团队间的合作都有一定的指导意义。在学校里没有教给你的一项本领就是怎样做一个好的代码审查(CR)。你学习了…

[Vue] 13.Vue中的双向绑定(2) ----指令修饰符

一、指令修饰符 ‘.lazy’: 失焦触发事件 <script>const app Vue.createApp({data() {return {message: hello}},template: <div>{{message}}<input v-model.lazy"message" /></div>,});const vm app.mount(#root)</script> ‘.nu…

使用sql server进行分布式查询 (转)

可以使用sql-server企业管理器进行建立&#xff0c;注意其中的rpc及rpc out两项&#xff0c;也可以使用sql语句来完成定义&#xff0c;主要涉及到三个存储过程 sp_addlinkedserver&#xff0c;sp_serveroption和sp_addlinkedsrvlogin&#xff0c;以下是三个存储过程的语法&…

[Spring]@Autowired,@Required,@Qualifier注解

Required注解 Required注解用于setter方法,表明这个属性是必要的,不可少的,必须注入值 假设有个测试类,里面有name和password两个属性 我给两个属性的setter方法都加了Required注解 package com.example.demo1.Implements;import com.example.demo1.Interface.UserService; imp…

python去掉字符串中空格的方法

1.strip()&#xff1a;把头和尾的空格去掉 2.lstrip()&#xff1a;把左边的空格去掉 3.rstrip()&#xff1a;把右边的空格去掉 4.replace(c1,c2)&#xff1a;把字符串里的c1替换成c2。故可以用replace( ,)来去掉字符串里的所有空格 5.split()&#xff1a;通过指定分隔符对字符串…

[Vue] 14.Vue中的组件:创建子组件以及在父组件中用子组件

一、父组件 创建父组件的实例如下&#xff1a; <script>const app Vue.createApp({template: <div>hello world</div>});const vm app.mount(#root)</script>定义两个全局子组件‘hello’和’world’ <script>const app Vue.createApp({te…

中英文词频统计

#英文小说 词频统计fo open(gc.txt, r, encodingutf-8)#提取字符串gc fo.read().lower()fo.close()print(gc)运行结果&#xff1a; strgc str.lower(gc) #换小写 sep .,;;!?~~-_... #替换字符 for ch in sep: gc gc.replace(ch, )print(gc)运行结果&#xff1a; str…