<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>费尔南多的博客</title><link>https://sxsmall.cn/</link><description>Good Luck To You!</description><item><title>弹窗重写上传事件faupload,上传后ajax可验证文件内容</title><link>https://sxsmall.cn/?id=5</link><description>&lt;pre class=&quot;prism-highlight prism-language-javascript&quot;&gt;//添加页面的上传回调事件
add:&amp;nbsp;function&amp;nbsp;()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;$(&amp;quot;#faupload-file&amp;quot;).data(&amp;quot;upload-success&amp;quot;,&amp;nbsp;function(btn,data,&amp;nbsp;ret){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//添加页面上传回调
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log(31231);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;Controller.api.bindevent();//放后面&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Wed, 26 Feb 2025 16:13:24 +0800</pubDate></item><item><title>composer install 和 composer update 的区别</title><link>https://sxsmall.cn/?id=4</link><description>&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;比如项目打算通过composer引入一个第三方的日志库&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;1.该项目composer未使用过的情况下：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;手动建立一个composer.json文件，里面指定好需要的版本，然后composer install,安装（下载到vendor）完成后会生成一个composer.lock文件&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;2.项目composer已使用过的情况下：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;直接在composer.json里面增加一行需要的依赖，然后composer install。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;注意之前需手动删除composer.lock（否则会抛出警告），如果不想这么麻烦，可直接require monolog/monolog:1.1.*，依赖下载完成后，会同步到composer.json和composer.lock文件中。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;注意&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果直接执行require时不加版本号，composer会根据本地php版本选取适配的版本，不过如在composer.json中已经声明了版本，那么会直接使用composer.json里的插件版本，不管本地php是否适配。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;升级monolog版本&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;先在composer.json里修改指定的版本后，执行composer update操作，注意不指定具体依赖名，直接依赖包执行composer update，程序会对比composer.json和composer.lock文件，找出差异的依赖进行升级，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;也可以直接运行 update monolog/monolog 1.2.* ，依赖更新后会同步到composer.json和composer.lock中。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;一句话就是：install先读lock再读json（后者更新到lock）。update直接读json，后更新到lock&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;不想操作json表就直接：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;1.初次引入 composer require monolog/monolog:1.1.*&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;2.更新单个 composer update monolog/monolog 1.2.*&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;提示，composer.json和composer.lock应放入git版本库，vendor目录则直接屏蔽，其他开发人员pull代码后install安装依赖后可以与你保持一致。&lt;/span&gt;&lt;/p&gt;</description><pubDate>Fri, 07 Jul 2023 15:21:18 +0800</pubDate></item><item><title>Vue3 基础 – 快速上手</title><link>https://sxsmall.cn/?id=3</link><description>&lt;h2 id=&quot;toc-0&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 36px; font-family: Gilroy; font-weight: 400; overflow: hidden; color: rgb(3, 3, 3); border-bottom: 1px solid rgb(239, 239, 239); padding-bottom: 6px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;在 HTML 网页中使用 vue3 的3个基本步骤&lt;/h2&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;通过&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;script&lt;/code&gt;&amp;nbsp;标签的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;src&lt;/code&gt;&amp;nbsp;属性，在当前网页中全局引入 vue3 的脚本文件：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;script&amp;nbsp;src=&amp;quot;https://unpkg.com/vue@3/dist/vue.global.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;创建 vue3 的单页面应用程序实例：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;//&amp;nbsp;2.1&amp;nbsp;从&amp;nbsp;Vue&amp;nbsp;对象中解构出&amp;nbsp;createApp&amp;nbsp;函数const&amp;nbsp;{&amp;nbsp;createApp&amp;nbsp;}&amp;nbsp;=&amp;nbsp;Vue//&amp;nbsp;2.2&amp;nbsp;调用&amp;nbsp;createApp&amp;nbsp;这个函数，就能够创建出一个单页面应用程序的实例const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp()//&amp;nbsp;2.3&amp;nbsp;调用&amp;nbsp;app&amp;nbsp;实例对象上的&amp;nbsp;mount()&amp;nbsp;函数，//&amp;nbsp;指定单页面应用程序&amp;nbsp;app，实际要控制页面上哪个区域的渲染app.mount(&amp;#39;#app&amp;#39;)&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;声明 vue3 的单页面应用程序实例，实际要控制的页面区域：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;注意：如果内容为空，则&amp;nbsp;vue3&amp;nbsp;会在提示一个警告消息：
[Vue&amp;nbsp;warn]:&amp;nbsp;Component&amp;nbsp;is&amp;nbsp;missing&amp;nbsp;template&amp;nbsp;or&amp;nbsp;render&amp;nbsp;function.&amp;nbsp;at&amp;nbsp;&amp;lt;App&amp;gt;&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 36px; font-family: Gilroy; font-weight: 400; overflow: hidden; color: rgb(3, 3, 3); border-bottom: 1px solid rgb(239, 239, 239); padding-bottom: 6px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2. 定义和渲染数据&lt;/h2&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;在调用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;createApp()&lt;/code&gt;&amp;nbsp;函数时，可以提供一个&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;对象&lt;/strong&gt;作为&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;配置参数&lt;/code&gt;，例如：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({&amp;nbsp;/*配置对象*/&amp;nbsp;})&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;如果想提供要渲染的数据，可以在步骤1的配置对象中，通过&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;data&lt;/code&gt;&amp;nbsp;节点提供渲染期间要使用的数据：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;//&amp;nbsp;2.1&amp;nbsp;注意：data&amp;nbsp;节点是一个函数
&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.2&amp;nbsp;在&amp;nbsp;data&amp;nbsp;函数内部，return&amp;nbsp;的这个对象，就是数据对象，
&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;要渲染的数据，可以直接写到这个对象中，例如&amp;nbsp;return&amp;nbsp;{&amp;nbsp;name:&amp;nbsp;&amp;#39;zs&amp;#39;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{}
&amp;nbsp;}})&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;在步骤2的 data 节点中，定义一个名为&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;name&lt;/code&gt;&amp;nbsp;的数据，值是&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;liulongbin&lt;/code&gt;：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name:&amp;nbsp;&amp;#39;liulongbin&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}})&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;在 vue3 控制的模板结构中，使用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;{{ 数据名 }}&lt;/code&gt;&amp;nbsp;语法，把数据渲染出来：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;大家好，我是：{{&amp;nbsp;name&amp;nbsp;}}&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;拓展：当我们修改 data 节点下的数据后，即可看到页面上的 HTML 内容会自动被刷新。这就是 vue 的强大之处：&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;数据驱动视图&lt;/strong&gt;。修改 data 数据的示例代码如下：&lt;/p&gt;&lt;pre class=&quot;language-javascript&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;app._instance.proxy.name&amp;nbsp;=&amp;nbsp;&amp;#39;escook&amp;#39;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-2&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 36px; font-family: Gilroy; font-weight: 400; overflow: hidden; color: rgb(3, 3, 3); border-bottom: 1px solid rgb(239, 239, 239); padding-bottom: 6px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3. vue3 中常用的渲染指令&lt;/h2&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;在 vue 中，指令是带有&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-&lt;/code&gt;&amp;nbsp;前缀的特殊 attribute，它是 vue 提供的特殊语法，大家有必要掌握 vue 中常用指令的使用。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;指令能够辅助前端程序员高效地把数据渲染为 HTML 的结构，而程序员不需要调用任何操作 DOM 的 API。&lt;/p&gt;&lt;h3 id=&quot;toc-3&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3.0 常用指令的分类&lt;/h3&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p&gt;内容渲染指令&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;属性绑定指令&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;双向绑定指令&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;条件渲染指令&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;事件绑定指令&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;列表渲染指令&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;toc-4&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3.1 内容渲染指令&lt;/h3&gt;&lt;h4 id=&quot;toc-5&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1. 插值表达式&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;插值表达式（又叫做：Mustache）的语法为&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;{{ }}&lt;/code&gt;，vue 在解析模板期间，会把&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;{{ }}&lt;/code&gt;&amp;nbsp;所在的位置，替换为对应的数据值，例如：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;h1&amp;gt;大家好，我是：{{&amp;nbsp;name&amp;nbsp;}}&amp;lt;/h1&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;vue 会把&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;name&lt;/code&gt;&amp;nbsp;的值，替换到&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;{{ name }}&lt;/code&gt;&amp;nbsp;所在的位置。&lt;/p&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;注意：插值表达式 {{ }} 是唯一一个不以 v- 前缀开头的指令。&lt;/p&gt;&lt;/blockquote&gt;&lt;h4 id=&quot;toc-6&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2. v-text&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-text&lt;/code&gt;&amp;nbsp;指令用来&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;填充&lt;/strong&gt;&amp;nbsp;HTML 元素的内容，如果 HTML 元素内部有其它内容存在，则会被&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;覆盖&lt;/strong&gt;掉。语法格式如下：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;h3&amp;nbsp;v-text=&amp;quot;msg&amp;quot;&amp;gt;是兄弟就来&amp;lt;/h3&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据为：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg:&amp;nbsp;&amp;#39;砍我吧&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;注意：由于 v-text 指令存在覆盖已有内容的问题，所以在实际开发中它很少被用到。最常用的还是 {{ }} 插值表达式，因为它只是占位符，不会覆盖已有内容。&lt;/p&gt;&lt;/blockquote&gt;&lt;h4 id=&quot;toc-7&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3. v-html&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-html&lt;/code&gt;&amp;nbsp;指令用来渲染&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;带有 HTML 标记的文本内容&lt;/strong&gt;，它可以把 HTML 标记解析为&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;真正的 HTML 元素&lt;/strong&gt;，并插入到模板中渲染。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;而插值表达式和 v-text 指令只会把 HTML 标记渲染为纯文本，而不是 HTML。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;v-html 的语法格式如下：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-html=&amp;quot;rawHtml&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据为：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rawHtml:&amp;nbsp;&amp;#39;&amp;lt;span&amp;nbsp;style=&amp;quot;color:&amp;nbsp;red;&amp;quot;&amp;gt;少年强则国强&amp;lt;/span&amp;gt;&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;h3 id=&quot;toc-8&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3.2 属性绑定指令&lt;/h3&gt;&lt;h4 id=&quot;toc-9&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1. v-bind&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-bind&lt;/code&gt;&amp;nbsp;指令用来为元素的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;属性&lt;/strong&gt;绑定&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;动态的属性值&lt;/strong&gt;。指令语法如下：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-bind:title=&amp;quot;titleMsg&amp;quot;&amp;gt;xxx&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据为：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;titleMsg:&amp;nbsp;&amp;#39;哇哈哈&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;又例如，为图片的 src 属性动态绑定属性的值：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;img&amp;nbsp;v-bind:src=&amp;quot;url&amp;quot;&amp;nbsp;/&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据为：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url:&amp;nbsp;&amp;#39;https://img.yzcdn.cn/vant/cat.jpeg&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;h4 id=&quot;toc-10&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2. v-bind 的简写&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;在实际开发中，&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-bind&lt;/code&gt;&amp;nbsp;指令的使用频率非常高，为了简化它的写法，vue 规定&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-bind&lt;/code&gt;&amp;nbsp;指令可以简写为英文的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;:&lt;/code&gt;&amp;nbsp;且二者是完全等价的。如上面的例子可以使用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;:&lt;/code&gt;&amp;nbsp;简写为：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;:title=&amp;quot;titleMsg&amp;quot;&amp;gt;xxx&amp;lt;/div&amp;gt;&amp;lt;img&amp;nbsp;:src=&amp;quot;url&amp;quot;&amp;nbsp;/&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据为：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;titleMsg:&amp;nbsp;&amp;#39;哇哈哈&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url:&amp;nbsp;&amp;#39;https://img.yzcdn.cn/vant/cat.jpeg&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;注意：今后在 vue 项目开发中，只要看到某个属性前面出现了英文的 : 那么，一定是为这个属性绑定了动态的值。&lt;/p&gt;&lt;/blockquote&gt;&lt;h4 id=&quot;toc-11&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3. 绑定布尔值&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;在 vue 中，某些属性的取值可以是布尔值 true 或 false，表示当前的属性是否应该&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;应用于当前的元素&lt;/strong&gt;。例如&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;disabled&lt;/code&gt;&amp;nbsp;属性：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;禁用按钮A&amp;nbsp;--&amp;gt;&amp;lt;button&amp;nbsp;:disabled=&amp;quot;true&amp;quot;&amp;gt;按钮A&amp;lt;/button&amp;gt;&amp;lt;!--&amp;nbsp;不禁用按钮B&amp;nbsp;--&amp;gt;&amp;lt;button&amp;nbsp;:disabled=&amp;quot;false&amp;quot;&amp;gt;按钮B&amp;lt;/button&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;与之类似的，还有 radio 和 checkbox 的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;checked&lt;/code&gt;&amp;nbsp;属性：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;默认选中“男”&amp;nbsp;--&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;radio&amp;quot;&amp;nbsp;name=&amp;quot;gender&amp;quot;&amp;nbsp;:checked=&amp;quot;true&amp;quot;&amp;gt;男&amp;lt;input&amp;nbsp;type=&amp;quot;radio&amp;quot;&amp;nbsp;name=&amp;quot;gender&amp;quot;&amp;gt;女&amp;lt;!--&amp;nbsp;默认选中“足球”和“乒乓球”&amp;nbsp;--&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;checkbox&amp;quot;&amp;nbsp;name=&amp;quot;hobby&amp;quot;&amp;gt;篮球&amp;lt;input&amp;nbsp;type=&amp;quot;checkbox&amp;quot;&amp;nbsp;name=&amp;quot;hobby&amp;quot;&amp;nbsp;:checked=&amp;quot;true&amp;quot;&amp;gt;足球&amp;lt;input&amp;nbsp;type=&amp;quot;checkbox&amp;quot;&amp;nbsp;name=&amp;quot;hobby&amp;quot;&amp;nbsp;:checked=&amp;quot;true&amp;quot;&amp;gt;乒乓球&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;另外，表单元素&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;select&lt;/code&gt;&amp;nbsp;下的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;option&lt;/code&gt;&amp;nbsp;选项的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;selected&lt;/code&gt;&amp;nbsp;属性，也可以绑定布尔值：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;select&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;北京&amp;quot;&amp;gt;北京&amp;lt;/option&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;上海&amp;quot;&amp;nbsp;:selected=&amp;quot;true&amp;quot;&amp;gt;上海&amp;lt;/option&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;广州&amp;quot;&amp;gt;广州&amp;lt;/option&amp;gt;&amp;lt;/select&amp;gt;&lt;/pre&gt;&lt;h4 id=&quot;toc-12&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;4. 动态绑定多个值&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;如果要为某个元素&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;同时绑定多个&lt;/strong&gt;动态的属性值，可以把多个动态属性封装为一个 JavaScript 对象：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;propObj&amp;nbsp;对象中封装了一系列属性的键值对
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;attrsObj:&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id:&amp;nbsp;&amp;#39;box&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;class:&amp;nbsp;&amp;#39;container&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;title:&amp;nbsp;&amp;#39;布局容器&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;通过&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;不带参数的&lt;/strong&gt;&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-bind&lt;/code&gt;&amp;nbsp;指令，即可方便的把 attrsObj 对象中封装的属性，一次性绑定到对应的元素上：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-bind=&amp;quot;attrsObj&amp;quot;&amp;gt;顶部&amp;nbsp;header&amp;nbsp;区域&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;注意：不带参数的 v-bind 指令，指的是省略了&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 11.05px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;:属性名&lt;/code&gt;&amp;nbsp;的用法。&lt;/p&gt;&lt;/blockquote&gt;&lt;h4 id=&quot;toc-13&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;5. 拓展：使用 JavaScript 表达式&lt;/h4&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;在 vue 的数据绑定中，除了支持简单的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;属性名绑定&lt;/strong&gt;之外，还支持&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;完整的 JavaScript 表达式绑定&lt;/strong&gt;。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;例如，以下这些都属于简单的属性名绑定，它们是直接把 data 中数据项的名字，绑定到了模板中：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;gt;我是：{{&amp;nbsp;name&amp;nbsp;}}&amp;lt;/div&amp;gt;&amp;lt;div&amp;nbsp;v-text=&amp;quot;msg&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img&amp;nbsp;:src=&amp;quot;url&amp;quot;&amp;nbsp;/&amp;gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;除此之外，还支持表达式的绑定，例如：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;函数的调用&amp;nbsp;&amp;amp;&amp;nbsp;数学运算&amp;nbsp;--&amp;gt;&amp;lt;div&amp;gt;我是：{{&amp;nbsp;name.toUpperCase()&amp;nbsp;}}，我今年{{&amp;nbsp;age&amp;nbsp;+&amp;nbsp;1&amp;nbsp;}}岁了。&amp;lt;/div&amp;gt;&amp;lt;!--&amp;nbsp;函数的调用&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;v-text=&amp;quot;msg.split(&amp;#39;&amp;#39;).reverse().join(&amp;#39;&amp;#39;)&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;!--&amp;nbsp;字符串的拼接&amp;nbsp;--&amp;gt;&amp;lt;img&amp;nbsp;:src=&amp;quot;&amp;#39;https://img.yzcdn.cn/vant/&amp;#39;&amp;nbsp;+&amp;nbsp;url&amp;quot;&amp;nbsp;/&amp;gt;&amp;lt;!--&amp;nbsp;三元表达式&amp;nbsp;--&amp;gt;&amp;lt;div&amp;gt;{{&amp;nbsp;age&amp;nbsp;&amp;gt;=&amp;nbsp;18&amp;nbsp;?&amp;nbsp;&amp;#39;抽烟喝酒烫头&amp;#39;&amp;nbsp;:&amp;nbsp;&amp;#39;可乐牛奶娃哈哈&amp;#39;&amp;nbsp;}}&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name:&amp;nbsp;&amp;#39;liulongbin&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age:&amp;nbsp;17,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg:&amp;nbsp;&amp;#39;冯绍峰&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url:&amp;nbsp;&amp;#39;cat.jpeg&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}})&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;toc-14&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3.3 双向绑定指令&lt;/h3&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-model&lt;/code&gt;&amp;nbsp;双向绑定指令，简化了&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;表单元素&lt;/strong&gt;的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;赋值和取值&lt;/strong&gt;操作。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-model&lt;/code&gt;&amp;nbsp;的作用：&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p&gt;data 数据源发生变化，自动重新渲染页面&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;表单数据发生变化，自动更新到 data 数据源中&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;toc-15&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1. 文本框的双向绑定&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;input 元素通过 v-model 指令，可以方便地进行赋值和取值，示例代码如下：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;p&amp;gt;Message&amp;nbsp;的值是：{{&amp;nbsp;message&amp;nbsp;}}&amp;lt;/p&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;text&amp;quot;&amp;nbsp;v-model=&amp;quot;message&amp;quot;&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;message:&amp;nbsp;&amp;#39;hello&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;h4 id=&quot;toc-16&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2. 多行文本框的双向绑定&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;textarea 元素通过 v-model 指令，可以方便地进行赋值和取值，示例代码如下：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;p&amp;gt;Message&amp;nbsp;的值是：&amp;lt;/p&amp;gt;&amp;lt;pre&amp;gt;{{&amp;nbsp;message&amp;nbsp;}}&amp;lt;/pre&amp;gt;&amp;lt;textarea&amp;nbsp;v-model=&amp;quot;message&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;注意：这里的&amp;nbsp;\n&amp;nbsp;是换行符
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;message:&amp;nbsp;&amp;#39;hello&amp;nbsp;\nworld.&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;h4 id=&quot;toc-17&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3. 复选框的双向绑定&lt;/h4&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;单一复选框&lt;/strong&gt;的双向绑定，绑定的是&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;布尔类型&lt;/strong&gt;的值：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;p&amp;gt;复选框选中的flag值为：{{flag}}&amp;lt;/p&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;checkbox&amp;quot;&amp;nbsp;v-model=&amp;quot;flag&amp;quot;&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;是否被选中
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;flag:&amp;nbsp;false
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}})&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;多个复选框&lt;/strong&gt;的双向绑定，绑定的是&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;数组类型&lt;/strong&gt;的值，而且每个 checkbox 必须通过&amp;nbsp;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;value 属性&lt;/strong&gt;提供&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;选中项的值&lt;/strong&gt;：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;p&amp;gt;多个复选框选中的&amp;nbsp;hobbies&amp;nbsp;值为：{{&amp;nbsp;hobbies&amp;nbsp;}}&amp;lt;/p&amp;gt;&amp;lt;label&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;checkbox&amp;quot;&amp;nbsp;v-model=&amp;quot;hobbies&amp;quot;&amp;nbsp;value=&amp;quot;篮球&amp;quot;&amp;gt;篮球&amp;lt;/label&amp;gt;&amp;lt;label&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;checkbox&amp;quot;&amp;nbsp;v-model=&amp;quot;hobbies&amp;quot;&amp;nbsp;value=&amp;quot;足球&amp;quot;&amp;gt;足球&amp;lt;/label&amp;gt;&amp;lt;label&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;checkbox&amp;quot;&amp;nbsp;v-model=&amp;quot;hobbies&amp;quot;&amp;nbsp;value=&amp;quot;冰球&amp;quot;&amp;gt;冰球&amp;lt;/label&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;选中的值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;hobbies:&amp;nbsp;[]
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}})&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;toc-18&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;4. 单选按钮的双向绑定&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;单选按钮的特点是多选一，所以对单选按钮进行双向绑定时，需要把多个单选按钮通过 v-model 指令绑定到同一个数据源，并通过 value 属性指定选中后的值：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;p&amp;gt;单选按钮选中的&amp;nbsp;gender&amp;nbsp;值为：{{&amp;nbsp;gender&amp;nbsp;}}&amp;lt;/p&amp;gt;&amp;lt;label&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;radio&amp;quot;&amp;nbsp;v-model=&amp;quot;gender&amp;quot;&amp;nbsp;value=&amp;quot;男&amp;quot;&amp;gt;男&amp;lt;/label&amp;gt;&amp;lt;label&amp;gt;&amp;lt;input&amp;nbsp;type=&amp;quot;radio&amp;quot;&amp;nbsp;v-model=&amp;quot;gender&amp;quot;&amp;nbsp;value=&amp;quot;女&amp;quot;&amp;gt;女&amp;lt;/label&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;选中的值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gender:&amp;nbsp;&amp;#39;男&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;h4 id=&quot;toc-19&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;5. 选择器的双向绑定&lt;/h4&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;单选&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;选择器&lt;/strong&gt;的双向绑定，只允许选中一个值：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;p&amp;gt;选中的城市为：{{&amp;nbsp;city&amp;nbsp;}}&amp;lt;/p&amp;gt;&amp;lt;select&amp;nbsp;v-model=&amp;quot;city&amp;quot;&amp;gt;
&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;&amp;quot;&amp;gt;请选择&amp;lt;/option&amp;gt;
&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;beijing&amp;quot;&amp;gt;北京&amp;lt;/option&amp;gt;
&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;shanghai&amp;quot;&amp;gt;上海&amp;lt;/option&amp;gt;
&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;nanjing&amp;quot;&amp;gt;南京&amp;lt;/option&amp;gt;&amp;lt;/select&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;city:&amp;nbsp;&amp;#39;&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}})&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;多选&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;选择器&lt;/strong&gt;的双向绑定，允许选中多个值，所以需要绑定&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;数组格式&lt;/strong&gt;的数据源：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;p&amp;gt;选中的城市为：{{&amp;nbsp;areas&amp;nbsp;}}&amp;lt;/p&amp;gt;&amp;lt;select&amp;nbsp;v-model=&amp;quot;areas&amp;quot;&amp;nbsp;multiple&amp;gt;
&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;shunyi&amp;quot;&amp;gt;顺义区&amp;lt;/option&amp;gt;
&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;haidian&amp;quot;&amp;gt;海淀区&amp;lt;/option&amp;gt;
&amp;nbsp;&amp;lt;option&amp;nbsp;value=&amp;quot;daxing&amp;quot;&amp;gt;大兴区&amp;lt;/option&amp;gt;&amp;lt;/select&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; color: rgb(0, 0, 0); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;areas:&amp;nbsp;[]
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}})&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;toc-20&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;6. v-model 的 .lazy 修饰符&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;默认情况下，&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-model&lt;/code&gt;&amp;nbsp;会在每次&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;input&lt;/code&gt;&amp;nbsp;事件后更新数据。可以添加&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;.lazy&lt;/code&gt;&amp;nbsp;修饰符来改为在每次&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;change&lt;/code&gt;&amp;nbsp;事件后更新数据：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;input&amp;nbsp;v-model.lazy=&amp;quot;msg&amp;quot;&amp;nbsp;/&amp;gt;&lt;/pre&gt;&lt;h4 id=&quot;toc-21&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;7. v-model 的 .number 修饰符&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;如果你想让用户输入自动转换为数字，你可以在&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-model&lt;/code&gt;&amp;nbsp;后添加&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;.number&lt;/code&gt;&amp;nbsp;修饰符来管理输入：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;input&amp;nbsp;v-model.number=&amp;quot;age&amp;quot;&amp;nbsp;/&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;注意：&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p&gt;如果该值无法被&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;parseFloat()&lt;/code&gt;&amp;nbsp;处理，那么将返回原始值。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;number&lt;/code&gt;&amp;nbsp;修饰符会在输入框有&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;type=&amp;quot;number&amp;quot;&lt;/code&gt;&amp;nbsp;时自动启用。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;toc-22&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;8. v-model 的 .trim 修饰符&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;如果你想要默认自动去除用户输入内容中两端的空格，你可以在&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-model&lt;/code&gt;&amp;nbsp;后添加&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;.trim&lt;/code&gt;&amp;nbsp;修饰符：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;input&amp;nbsp;v-model.trim=&amp;quot;msg&amp;quot;&amp;nbsp;/&amp;gt;&lt;/pre&gt;&lt;h3 id=&quot;toc-23&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3.4 条件渲染指令&lt;/h3&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;条件渲染指令用来条件性地渲染页面上的某一部分内容。只有表达式的条件成立，才会真正渲染这一部分的内容。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;常用的条件渲染指令是&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;、&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else-if&lt;/code&gt;。其中，&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;指令可以单独使用，也可以结合&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else-if&lt;/code&gt;&amp;nbsp;指令实现&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;两个&lt;/strong&gt;或&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;多个&lt;/strong&gt;条件的按需渲染。&lt;/p&gt;&lt;h4 id=&quot;toc-24&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1. v-if 的使用&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;v-if 的语法格式如下：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-if=&amp;quot;表达式&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;其中，只有表达式的返回值为 true 时，才会真正渲染被 v-if 指令控制的 div 元素。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;如果 v-if 的表达式返回值为 false，则被 v-if 指令控制的 div 不会被渲染到浏览器中。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;例如：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-if=&amp;quot;flag&amp;quot;&amp;gt;无敌是多么的寂寞&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据为：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;flag:&amp;nbsp;true
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;h4 id=&quot;toc-25&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2. v-if 结合 v-else 的使用&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;指令可以结合&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else&lt;/code&gt;&amp;nbsp;指令一起使用。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;当&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;条件为真&lt;/strong&gt;时渲染被&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;指令控制的元素，当&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;条件为假&lt;/strong&gt;时渲染被&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else&lt;/code&gt;&amp;nbsp;指令控制的元素。例如：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-if=&amp;quot;age&amp;nbsp;&amp;gt;=&amp;nbsp;18&amp;quot;&amp;gt;抽烟喝酒烫头&amp;lt;/div&amp;gt;&amp;lt;div&amp;nbsp;v-else&amp;gt;牛奶可乐娃哈哈&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;注意：v-else 指令不需要通过 = 指定相应的表达式，因为&amp;nbsp;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;v-else 是兜底的条件&lt;/strong&gt;，只要前面的所有条件都不满足，那么必然会触发 v-else 的执行。&lt;/p&gt;&lt;/blockquote&gt;&lt;h4 id=&quot;toc-26&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3. v-if 结合 v-else-if 和 v-else 的使用&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;指令可以结合&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else-if&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else&lt;/code&gt;&amp;nbsp;指令一起使用，从而组成复杂的条件渲染逻辑。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;当&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;或某个&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else-if&lt;/code&gt;&amp;nbsp;相应的条件为真时，被控制的元素才会被渲染。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;最后的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else&lt;/code&gt;&amp;nbsp;依然是兜底的条件，当所有的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-else-if&lt;/code&gt;&amp;nbsp;条件都不成立时，才会触发 v-else 的执行。例如：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-if=&amp;quot;score&amp;nbsp;===&amp;nbsp;&amp;#39;A&amp;#39;&amp;quot;&amp;gt;优秀&amp;lt;/div&amp;gt;&amp;lt;div&amp;nbsp;v-else-if=&amp;quot;score&amp;nbsp;===&amp;nbsp;&amp;#39;B&amp;#39;&amp;quot;&amp;gt;良好&amp;lt;/div&amp;gt;&amp;lt;div&amp;nbsp;v-else-if=&amp;quot;score&amp;nbsp;===&amp;nbsp;&amp;#39;C&amp;#39;&amp;quot;&amp;gt;一般&amp;lt;/div&amp;gt;&amp;lt;div&amp;nbsp;v-else&amp;gt;差&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;对应的数据为：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;data()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;score:&amp;nbsp;&amp;#39;A&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})&lt;/pre&gt;&lt;h4 id=&quot;toc-27&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;4. &amp;lt;template&amp;gt; 上的 v-if&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;正常情况下&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;指令只能控制&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;单个元素&lt;/strong&gt;的显示和隐藏。如果需要使用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;控制&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;一组元素&lt;/strong&gt;的显示和隐藏，就需要在这一组元素之外&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;包裹一个 div 作为容器&lt;/strong&gt;，并将&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;指令&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;应用于 div 容器之上&lt;/strong&gt;，例如：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;v-if=&amp;quot;true&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;咏鹅&amp;lt;/h1&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;鹅鹅鹅，曲项向天歌。&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;白毛浮绿水，红掌拨清波。&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;这么做虽然能实现需求，但会在页面上渲染出一个多余的 div 容器。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;更好的方案是使用 vue 内置的&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;&amp;lt;template&amp;gt;&lt;/code&gt;&amp;nbsp;元素作为外层包裹性质的容器，因为&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;它不会被渲染为实际的元素，只起到包裹性质的作用&lt;/strong&gt;。例如：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;template&amp;nbsp;v-if=&amp;quot;true&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;咏鹅&amp;lt;/h1&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;鹅鹅鹅，曲项向天歌。&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;白毛浮绿水，红掌拨清波。&amp;lt;/p&amp;gt;&amp;lt;/template&amp;gt;&lt;/pre&gt;&lt;h4 id=&quot;toc-28&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;5. v-show 指令的使用&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;另一个可以用来实现条件渲染的指令是&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-show&lt;/code&gt;。它的语法格式如下：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;padding: 1em; border-radius: 6px; background-color: rgb(245, 242, 240); box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); position: relative; text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;h1&amp;nbsp;v-show=&amp;quot;flag&amp;quot;&amp;gt;Hello!&amp;lt;/h1&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;如果表达式的值为&amp;nbsp;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;true&lt;/strong&gt;，则被控制的元素会被&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;显示&lt;/strong&gt;；&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;如果表达式的值为&amp;nbsp;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;false&lt;/strong&gt;，则被控制的元素会被&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;隐藏&lt;/strong&gt;。&lt;/p&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;注意：v-show 指令不支持在 &amp;lt;template&amp;gt;&amp;nbsp;元素上使用，也不能和 v-else 搭配使用。&lt;/p&gt;&lt;/blockquote&gt;&lt;h4 id=&quot;toc-29&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 24px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;6. v-if 和 v-show 的对比&lt;/h4&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;相同点：&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-show&lt;/code&gt;&amp;nbsp;指令都能控制元素的条件渲染。&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p&gt;如果表达式的值为&amp;nbsp;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;true&lt;/strong&gt;，则被控制的元素会被&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;显示&lt;/strong&gt;；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;如果表达式的值为&amp;nbsp;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;false&lt;/strong&gt;，则被控制的元素会被&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;隐藏&lt;/strong&gt;。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); margin-top: 10px !important; margin-bottom: 10px !important; outline: 0px !important;&quot;&gt;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;不同点：&lt;/strong&gt;&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;margin-bottom: 15px; width: 1395.55px; padding: 0px 0px 0px 25px; box-sizing: border-box; list-style-position: initial; list-style-image: initial; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;li&gt;&lt;p&gt;控制元素显示和隐藏的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;手段不同&lt;/strong&gt;：&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;指令会动态&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;创建&lt;/strong&gt;和&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;删除&lt;/strong&gt;被控制的元素，从而达到切换元素显示和隐藏的目的；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-show&lt;/code&gt;&amp;nbsp;指令仅&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;切换&lt;/strong&gt;了被控制元素上名为&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;display&lt;/code&gt;&amp;nbsp;的 CSS 属性，从而达到切换元素显示和隐藏的目的；&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;初始渲染&lt;/strong&gt;的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;性能&lt;/strong&gt;不同：&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;如果初始渲染时，表达式的值为 false，则 v-if 的性能更好。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;如果初始渲染时，表达式的值为 true，则二者性能相近。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;频繁切换&lt;/strong&gt;时的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;性能&lt;/strong&gt;不同：&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;如果需要频繁切换元素的显示和隐藏，则 v-show 的性能更好。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;如果不需要频繁切换元素的显示和隐藏，则可以忽略二者的性能差别。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;p&gt;总结：&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-if&lt;/code&gt;&amp;nbsp;有更高的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;切换开销&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;v-show&lt;/code&gt;&amp;nbsp;有更高的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;初始渲染开销&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;p&gt;&lt;br style=&quot;text-wrap: wrap;&quot;/&gt;&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; font-size: 36px; font-family: Gilroy; font-weight: 400; overflow: hidden; color: rgb(3, 3, 3); border-bottom: 1px solid rgb(239, 239, 239); padding-bottom: 6px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h2&gt;</description><pubDate>Sat, 01 Jul 2023 15:21:18 +0800</pubDate></item><item><title>Vue3 基础 – 计算属性 &amp;amp; 侦听器 &amp;amp; 样式绑定 &amp;amp; 模板引用</title><link>https://sxsmall.cn/?id=1</link><description>&lt;h1 style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 40px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1. setup 函数 &amp;amp; 组合式 API&lt;/h1&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;在前面的课程中，我们曾强调过：使用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;data()&lt;/code&gt;&amp;nbsp;函数声明响应式的数据、在&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;methods&lt;/code&gt;&amp;nbsp;节点下声明事件处理器，都是 Vue2 中的旧语法（&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;选项式API&lt;/strong&gt;）。这种旧语法的存在，主要是为了防止&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;断崖式升级&lt;/strong&gt;造成的老用户流失。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;在 Vue3 中，推出了&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;组合式 API&lt;/strong&gt;&amp;nbsp;的新概念，它可以极大提高功能模块的&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;封装性&lt;/strong&gt;和&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;复用性&lt;/strong&gt;。因此，官方推荐所有用户优先使用组合式 API。&lt;/p&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;在今后的开发中，为了维护老项目，我们可能会不得不用到选项式 API。除此之外，在开发新项目时，推荐大家优先使用组合式 API。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 36px; font-family: Gilroy; font-weight: 400; overflow: hidden; color: rgb(3, 3, 3); border-bottom: 1px solid rgb(239, 239, 239); padding-bottom: 6px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1.1 setup 函数&lt;/h2&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;setup()&lt;/code&gt;&amp;nbsp;函数是 Vue3 中组合式 API 的入口，它的语法格式如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;{&amp;nbsp;createApp&amp;nbsp;}&amp;nbsp;=&amp;nbsp;Vueconst&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;给模板使用的数据、事件处理器等，都要通过这个&amp;nbsp;return&amp;nbsp;的对象暴露给模板
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{}
&amp;nbsp;&amp;nbsp;}})app.mount(&amp;#39;#app&amp;#39;)&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;例如，在&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;setup&lt;/code&gt;&amp;nbsp;return 的对象中，声明一个数据&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;name&lt;/code&gt;：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;{&amp;nbsp;createApp&amp;nbsp;}&amp;nbsp;=&amp;nbsp;Vueconst&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;给模板使用的数据、事件处理器等，都要通过这个&amp;nbsp;return&amp;nbsp;的对象暴露给模板
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name:&amp;nbsp;&amp;#39;liulongbin&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})app.mount(&amp;#39;#app&amp;#39;)&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;紧接着，在模板中即可使用名为 name 的数据了：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;模板&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;{{&amp;nbsp;name&amp;nbsp;}}&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;注意：刚才定义的 name，并非是响应式的数据，所以基于 app._instance.proxy.name 修改它的值后，不会触发视图的重新渲染。&lt;/p&gt;&lt;/blockquote&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 36px; font-family: Gilroy; font-weight: 400; overflow: hidden; color: rgb(3, 3, 3); border-bottom: 1px solid rgb(239, 239, 239); padding-bottom: 6px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1.2 组合式 API&lt;/h2&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;组合式 API 是 Vue3 提供的一系列函数。例如，可以使用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;reactive()&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;ref()&lt;/code&gt;&amp;nbsp;这两个函数，来声明响应式的数据。&lt;/p&gt;&lt;h3 id=&quot;toc-2&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;1. reactive 函数&lt;/h3&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;reactive 函数用来定义响应式的数据对象，它的使用步骤如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;//&amp;nbsp;1.&amp;nbsp;从&amp;nbsp;Vue&amp;nbsp;上解构出&amp;nbsp;reactive&amp;nbsp;函数const&amp;nbsp;{&amp;nbsp;createApp,&amp;nbsp;reactive&amp;nbsp;}&amp;nbsp;=&amp;nbsp;Vueconst&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;调用&amp;nbsp;reactive&amp;nbsp;函数，定义响应式的数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;user&amp;nbsp;=&amp;nbsp;reactive({&amp;nbsp;name:&amp;nbsp;&amp;#39;zs&amp;#39;&amp;nbsp;})

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;3.&amp;nbsp;把响应式的数据，挂载到&amp;nbsp;return&amp;nbsp;的对象上，供模板使用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;user&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})app.mount(&amp;#39;#app&amp;#39;)&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;接下来，就可以在模板中使用响应式的数据&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;user&lt;/code&gt;&amp;nbsp;啦：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;模板&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;{{&amp;nbsp;user.name&amp;nbsp;}}&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;h3 id=&quot;toc-3&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2. 修改 reactive 数据&lt;/h3&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;如果想要点击按钮，修改&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;user.name&lt;/code&gt;&amp;nbsp;的值，我们可以在&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;setup&lt;/code&gt;&amp;nbsp;中定义事件的处理函数，并挂载到 return 的对象上，供模板使用：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;const&amp;nbsp;user&amp;nbsp;=&amp;nbsp;reactive({&amp;nbsp;name:&amp;nbsp;&amp;#39;liulongbin&amp;#39;&amp;nbsp;})

&amp;nbsp;&amp;nbsp;//&amp;nbsp;1.&amp;nbsp;定义处理函数
&amp;nbsp;&amp;nbsp;const&amp;nbsp;changeUserName&amp;nbsp;=&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;user.name&amp;nbsp;=&amp;nbsp;&amp;#39;escook&amp;#39;
&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;user,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;把处理函数，暴露给模板使用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;changeUserName&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;最后，在模板中，为&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;&amp;lt;button&amp;gt;&lt;/code&gt;&amp;nbsp;按钮绑定点击事件：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;模板&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;{{&amp;nbsp;user.name&amp;nbsp;}}&amp;lt;/h1&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;3.&amp;nbsp;绑定事件处理器&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;button&amp;nbsp;@click=&amp;quot;changeUserName&amp;quot;&amp;gt;按钮&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;reactive 函数的缺点：只能为引用类型的数据创建响应式数据对象，无法将值类型的数据转化为响应式数据。&lt;/p&gt;&lt;/blockquote&gt;&lt;h3 id=&quot;toc-4&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;3. ref 函数&lt;/h3&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;ref 函数用来将值类型的数据转化为响应式数据，它的基本用法如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;//&amp;nbsp;1.&amp;nbsp;从&amp;nbsp;Vue&amp;nbsp;中结构出&amp;nbsp;ref&amp;nbsp;函数const&amp;nbsp;{&amp;nbsp;createApp,&amp;nbsp;ref&amp;nbsp;}&amp;nbsp;=&amp;nbsp;Vueconst&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;&amp;nbsp;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;调用&amp;nbsp;ref&amp;nbsp;函数，创建响应式数据&amp;nbsp;count，其初始值为&amp;nbsp;0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;count&amp;nbsp;=&amp;nbsp;ref(0)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;3.&amp;nbsp;把响应式数据&amp;nbsp;count，暴露给模板使用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}})app.mount(&amp;#39;#app&amp;#39;)&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;紧接着，就可以在模板中使用 count 了：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;模板&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;{{&amp;nbsp;count&amp;nbsp;}}&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;h3 id=&quot;toc-5&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;4. 修改 ref 数据&lt;/h3&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;如果想要点击按钮，修改&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;count&lt;/code&gt;&amp;nbsp;的值，则需要在&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;setup&lt;/code&gt;&amp;nbsp;函数中定义事件的处理函数，并挂载到 return 的对象上，供模板使用：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;const&amp;nbsp;count&amp;nbsp;=&amp;nbsp;ref(0)

&amp;nbsp;&amp;nbsp;//&amp;nbsp;1.&amp;nbsp;定义处理函数（注意：在&amp;nbsp;js&amp;nbsp;中必须使用&amp;nbsp;.value&amp;nbsp;来访问&amp;nbsp;ref&amp;nbsp;声明的响应式数据）
&amp;nbsp;&amp;nbsp;const&amp;nbsp;increase&amp;nbsp;=&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count.value++
&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;把处理函数，暴露给模板使用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;increase&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;最后，在模板中，为&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;&amp;lt;button&amp;gt;&lt;/code&gt;&amp;nbsp;按钮绑定点击事件：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;模板&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;{{&amp;nbsp;count&amp;nbsp;}}&amp;lt;/h1&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;3.&amp;nbsp;绑定事件处理器&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;button&amp;nbsp;@click=&amp;quot;increase&amp;quot;&amp;gt;+1&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;注意：使用 ref 声明的响应式数据，在 js 中必须使用 .value 进行访问。在模板中不必使用 .value 进行访问，因为在模板中使用时会自动对 ref 数据进行解包。&lt;/p&gt;&lt;/blockquote&gt;&lt;h3 id=&quot;toc-6&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 30px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;5. 将对象赋值给 ref&lt;/h3&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;ref 函数除了接收&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;值类型&lt;/strong&gt;的数据之外，还可以将&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;对象类型的数据&lt;/strong&gt;转化为&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;响应式&lt;/strong&gt;数据。例如：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;//&amp;nbsp;1.&amp;nbsp;把对象赋值给&amp;nbsp;ref&amp;nbsp;作为初始值
&amp;nbsp;&amp;nbsp;const&amp;nbsp;info&amp;nbsp;=&amp;nbsp;ref({&amp;nbsp;name:&amp;nbsp;&amp;#39;liulongbin&amp;#39;,&amp;nbsp;age:&amp;nbsp;18&amp;nbsp;})

&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;定义处理函数
&amp;nbsp;&amp;nbsp;const&amp;nbsp;changeInfo&amp;nbsp;=&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;通过&amp;nbsp;info.value&amp;nbsp;分别为每个属性赋值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;info.value.name&amp;nbsp;=&amp;nbsp;&amp;#39;escook&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;info.value.age&amp;nbsp;=&amp;nbsp;22

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;直接给&amp;nbsp;info.value&amp;nbsp;赋新值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;info.value&amp;nbsp;=&amp;nbsp;{&amp;nbsp;name:&amp;nbsp;&amp;#39;escook&amp;#39;,&amp;nbsp;age:&amp;nbsp;22&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;//&amp;nbsp;3.&amp;nbsp;向模板暴露数据
&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;info,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;changeInfo&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;在模板中，直接使用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;info&lt;/code&gt;&amp;nbsp;即可，因为模板中会对 ref 数据自动解包：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;!--&amp;nbsp;模板&amp;nbsp;--&amp;gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;h1&amp;gt;{{&amp;nbsp;info.name&amp;nbsp;}}今年{{info.age}}岁了。&amp;lt;/h1&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;button&amp;nbsp;@click=&amp;quot;changeInfo&amp;quot;&amp;gt;修改&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;注意：如果&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;ref()&lt;/code&gt;&amp;nbsp;处理的是对象类型的数据，则内部会调用&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;reactive()&lt;/code&gt;&amp;nbsp;函数将对象数据转为响应式数据，然后挂载为&amp;nbsp;&lt;code style=&quot;box-sizing: inherit; font-size: 12.75px; color: rgb(233, 105, 0); background-color: rgb(240, 240, 241); display: inline-block; padding: 0px 6px; border-radius: 3px; outline: 0px !important; font-family: Gilroy !important;&quot;&gt;.value&lt;/code&gt;&amp;nbsp;属性。&lt;/p&gt;&lt;blockquote style=&quot;box-sizing: inherit; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239); font-family: Gilroy; font-size: 15px; text-wrap: wrap; outline: 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;最佳实践：尽量使用 ref() 来定义响应式数据，因为它既可以处理值类型数据，又可以处理对象类型的数据。&lt;/p&gt;&lt;/blockquote&gt;&lt;h1 style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 40px; font-family: Gilroy; font-weight: 400; color: rgb(3, 3, 3); text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2. 计算属性&lt;/h1&gt;&lt;p style=&quot;box-sizing: inherit; text-align: justify; font-family: Gilroy; line-height: 30px; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;计算属性可以避免程序员在模板中编写大段的 JavaScript 表达式，从而提高代码的整洁度和可维护性。&lt;/p&gt;&lt;h2 id=&quot;toc-7&quot; style=&quot;box-sizing: inherit; margin: 40px 0px 10px; line-height: normal; clear: both; font-size: 36px; font-family: Gilroy; font-weight: 400; overflow: hidden; color: rgb(3, 3, 3); border-bottom: 1px solid rgb(239, 239, 239); padding-bottom: 6px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot;&gt;2.1 基于模板中的表达式统计商品信息&lt;/h2&gt;&lt;ol style=&quot;box-sizing: border-box; list-style-position: initial; list-style-image: initial; margin-bottom: 15px; padding: 0px 0px 0px 25px; font-family: Gilroy; color: rgb(70, 70, 70); font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); outline: 0px !important;&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;定义购物车中的商品数据如下：&lt;/p&gt;&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; color: rgb(0, 0, 0); background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;const&amp;nbsp;{&amp;nbsp;createApp,&amp;nbsp;ref&amp;nbsp;}&amp;nbsp;=&amp;nbsp;Vueconst&amp;nbsp;app&amp;nbsp;=&amp;nbsp;createApp({
&amp;nbsp;setup()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购物车中的商品数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;goods&amp;nbsp;=&amp;nbsp;ref([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;id:&amp;nbsp;1,&amp;nbsp;name:&amp;nbsp;&amp;#39;红烧肉盖饭&amp;#39;,&amp;nbsp;price:&amp;nbsp;26,&amp;nbsp;count:&amp;nbsp;1&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;id:&amp;nbsp;2,&amp;nbsp;name:&amp;nbsp;&amp;#39;小酥肉&amp;#39;,&amp;nbsp;price:&amp;nbsp;12,&amp;nbsp;count:&amp;nbsp;1&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;id:&amp;nbsp;3,&amp;nbsp;name:&amp;nbsp;&amp;#39;冰镇可乐&amp;#39;,&amp;nbsp;price:&amp;nbsp;6,&amp;nbsp;count:&amp;nbsp;1&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;])

&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;goods&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}})app.mount(&amp;#39;#app&amp;#39;)&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;在模板中渲染购物车中的商品数据，并基于模板中的表达式计算商品的数量、总价、运费：&lt;/p&gt;&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; color: rgb(0, 0, 0); background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;&amp;lt;div&amp;nbsp;id=&amp;quot;app&amp;quot;&amp;gt;
&amp;nbsp;&amp;lt;ul&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;li&amp;nbsp;v-for=&amp;quot;item&amp;nbsp;in&amp;nbsp;goods&amp;quot;&amp;nbsp;:key=&amp;quot;item.id&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;商品名称：{{item.name}}&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;单价：{{&amp;nbsp;item.price&amp;nbsp;}}&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;购买数量：{{&amp;nbsp;item.count&amp;nbsp;}}&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt;
&amp;nbsp;&amp;lt;/ul&amp;gt;

&amp;nbsp;&amp;lt;hr&amp;gt;
&amp;nbsp;&amp;lt;div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;总计：&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;商品数量：{{&amp;nbsp;goods.reduce((total,&amp;nbsp;item)&amp;nbsp;=&amp;gt;&amp;nbsp;total&amp;nbsp;+=&amp;nbsp;item.count,&amp;nbsp;0)&amp;nbsp;}}&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;商品总价：{{&amp;nbsp;goods.reduce((total,&amp;nbsp;item)&amp;nbsp;=&amp;gt;&amp;nbsp;total&amp;nbsp;+=&amp;nbsp;item.price&amp;nbsp;*&amp;nbsp;item.count,&amp;nbsp;0)&amp;nbsp;}}元&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;配送费：{{&amp;nbsp;goods.reduce((total,&amp;nbsp;item)&amp;nbsp;=&amp;gt;&amp;nbsp;total&amp;nbsp;+=&amp;nbsp;item.price&amp;nbsp;*&amp;nbsp;item.count,&amp;nbsp;0)&amp;nbsp;&amp;gt;=&amp;nbsp;50&amp;nbsp;?&amp;nbsp;&amp;#39;免配送费&amp;#39;&amp;nbsp;:&amp;nbsp;&amp;#39;5元&amp;#39;&amp;nbsp;}}&amp;lt;/p&amp;gt;
&amp;nbsp;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;编写样式，为商品添加分割线：&lt;/p&gt;&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: inherit; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-width: 1px; border-style: solid; padding: 1em; border-color: rgb(232, 232, 232); border-radius: 6px; position: relative; color: rgb(0, 0, 0); background-color: rgb(245, 242, 240); text-shadow: rgb(255, 255, 255) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; overflow: auto; outline: 0px !important; line-height: 2.2em !important;&quot;&gt;li+li&amp;nbsp;{
&amp;nbsp;border-top:&amp;nbsp;1px&amp;nbsp;solid&amp;nbsp;#efefef;}&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: inherit; line-height: 30px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;在步骤2中，我们发现模板中掺杂了较为复杂的表达式；而且在&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;商品总价&lt;/strong&gt;和&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;配送费&lt;/strong&gt;中，两次用到了商品的总价，但每次都需要重新计算总价，无法实现数据的复用。&lt;/p&gt;&lt;blockquote style=&quot;box-sizing: inherit; outline: 0px !important; border-left: 5px solid rgb(202, 155, 82); padding-left: 15px; color: rgb(3, 3, 3); border-top-color: rgb(202, 155, 82); border-right-color: rgb(202, 155, 82); border-bottom-color: rgb(202, 155, 82); margin-left: 0px; margin-right: 0px; border-radius: 3px; background-color: rgb(239, 239, 239);&quot;&gt;&lt;p style=&quot;box-sizing: inherit; font-size: 13px; line-height: 30px; letter-spacing: 0.5px; opacity: 0.9; padding: 10px 0px; outline: 0px !important; margin-top: 10px !important; margin-bottom: 10px !important;&quot;&gt;基于这样的原因，我们可以利用&amp;nbsp;&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;computed 计算属性&lt;/strong&gt;，把模板中的表达式运算，封装到 JS 中，从而达到&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;简化模板&lt;/strong&gt;和&lt;strong style=&quot;box-sizing: inherit; outline: 0px !important;&quot;&gt;实现数据复用&lt;/strong&gt;的目的。&lt;/p&gt;&lt;/blockquote&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 01 Jun 2023 15:21:18 +0800</pubDate></item></channel></rss>