mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
2 lines
38 KiB
JavaScript
2 lines
38 KiB
JavaScript
/*! For license information please see 5573.bc995e99.js.LICENSE.txt */
|
|
(self.webpackChunk=self.webpackChunk||[]).push([["5573"],{66470:function(s,a,n){"use strict";n.r(a);var l=n("80681");let t=["innerHTML"];a.default={setup:()=>({html:""}),render:()=>((0,l.wg)(),(0,l.iD)("div",{class:"van-doc-markdown-body",innerHTML:'<h1>Checkbox \u590D\u9009\u6846</h1>\n<div class="van-doc-card"><h3 id="jie-shao" tabindex="-1">\u4ECB\u7ECD</h3>\n<p>\u5728\u4E00\u7EC4\u5907\u9009\u9879\u4E2D\u8FDB\u884C\u591A\u9009\u3002</p>\n</div><div class="van-doc-card"><h3 id="yin-ru" tabindex="-1">\u5F15\u5165</h3>\n<p>\u901A\u8FC7\u4EE5\u4E0B\u65B9\u5F0F\u6765\u5168\u5C40\u6CE8\u518C\u7EC4\u4EF6\uFF0C\u66F4\u591A\u6CE8\u518C\u65B9\u5F0F\u8BF7\u53C2\u8003<a href="#/zh-CN/advanced-usage#zu-jian-zhu-ce" target="_blank">\u7EC4\u4EF6\u6CE8\u518C</a>\u3002</p>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { createApp } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Checkbox</span>, <span class="hljs-title class_">CheckboxGroup</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</span>;\n\n<span class="hljs-keyword">const</span> app = <span class="hljs-title function_">createApp</span>();\napp.<span class="hljs-title function_">use</span>(<span class="hljs-title class_">Checkbox</span>);\napp.<span class="hljs-title function_">use</span>(<span class="hljs-title class_">CheckboxGroup</span>);\n</code></pre>\n</div><h2 id="dai-ma-yan-shi" tabindex="-1">\u4EE3\u7801\u6F14\u793A</h2>\n<div class="van-doc-card"><h3 id="ji-chu-yong-fa" tabindex="-1">\u57FA\u7840\u7528\u6CD5</h3>\n<p>\u901A\u8FC7 <code>v-model</code> \u7ED1\u5B9A\u590D\u9009\u6846\u7684\u52FE\u9009\u72B6\u6001\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span>></span>\u590D\u9009\u6846<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> checked = <span class="hljs-title function_">ref</span>(<span class="hljs-literal">true</span>);\n <span class="hljs-keyword">return</span> { checked };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="jin-yong-zhuang-tai" tabindex="-1">\u7981\u7528\u72B6\u6001</h3>\n<p>\u901A\u8FC7\u8BBE\u7F6E <code>disabled</code> \u5C5E\u6027\u53EF\u4EE5\u7981\u7528\u590D\u9009\u6846\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">disabled</span>></span>\u590D\u9009\u6846<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="zi-ding-yi-xing-zhuang" tabindex="-1">\u81EA\u5B9A\u4E49\u5F62\u72B6</h3>\n<p>\u5C06 <code>shape</code> \u5C5E\u6027\u8BBE\u7F6E\u4E3A <code>square</code>\uFF0C\u590D\u9009\u6846\u7684\u5F62\u72B6\u4F1A\u53D8\u6210\u65B9\u5F62\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox-group</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"square"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"a"</span>></span>\u590D\u9009\u6846 a<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"b"</span>></span>\u590D\u9009\u6846 b<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox-group</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> checked = <span class="hljs-title function_">ref</span>([<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>]);\n <span class="hljs-keyword">return</span> { checked };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="zi-ding-yi-yan-se" tabindex="-1">\u81EA\u5B9A\u4E49\u989C\u8272</h3>\n<p>\u901A\u8FC7 <code>checked-color</code> \u5C5E\u6027\u8BBE\u7F6E\u9009\u4E2D\u72B6\u6001\u7684\u56FE\u6807\u989C\u8272\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">checked-color</span>=<span class="hljs-string">"#ee0a24"</span>></span>\u590D\u9009\u6846<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="zi-ding-yi-da-xiao" tabindex="-1">\u81EA\u5B9A\u4E49\u5927\u5C0F</h3>\n<p>\u901A\u8FC7 <code>icon-size</code> \u5C5E\u6027\u53EF\u4EE5\u81EA\u5B9A\u4E49\u56FE\u6807\u7684\u5927\u5C0F\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">icon-size</span>=<span class="hljs-string">"24px"</span>></span>\u590D\u9009\u6846<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="zi-ding-yi-tu-biao" tabindex="-1">\u81EA\u5B9A\u4E49\u56FE\u6807</h3>\n<p>\u901A\u8FC7 <code>icon</code> \u63D2\u69FD\u81EA\u5B9A\u4E49\u56FE\u6807\uFF0C\u53EF\u4EE5\u901A\u8FC7 <code>slotProps</code> \u5224\u65AD\u662F\u5426\u4E3A\u9009\u4E2D\u72B6\u6001.</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span>></span>\n \u81EA\u5B9A\u4E49\u56FE\u6807\n <span class="hljs-tag"><<span class="hljs-name">template</span> #<span class="hljs-attr">icon</span>=<span class="hljs-string">"props"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">img</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"img-icon"</span> <span class="hljs-attr">:src</span>=<span class="hljs-string">"props.checked ? activeIcon : inactiveIcon"</span> /></span>\n <span class="hljs-tag"></<span class="hljs-name">template</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n\n<span class="hljs-tag"><<span class="hljs-name">style</span>></span><span class="language-css">\n <span class="hljs-selector-class">.img-icon</span> {\n <span class="hljs-attribute">height</span>: <span class="hljs-number">20px</span>;\n }\n</span><span class="hljs-tag"></<span class="hljs-name">style</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> checked = <span class="hljs-title function_">ref</span>(<span class="hljs-literal">true</span>);\n <span class="hljs-keyword">return</span> {\n checked,\n <span class="hljs-attr">activeIcon</span>:\n <span class="hljs-string">'https://fastly.jsdelivr.net/npm/@vant/assets/user-active.png'</span>,\n <span class="hljs-attr">inactiveIcon</span>:\n <span class="hljs-string">'https://fastly.jsdelivr.net/npm/@vant/assets/user-inactive.png'</span>,\n };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="zuo-ce-wen-ben" tabindex="-1">\u5DE6\u4FA7\u6587\u672C</h3>\n<p>\u5C06 <code>label-position</code> \u5C5E\u6027\u8BBE\u7F6E\u4E3A <code>\'left\'</code>\uFF0C\u53EF\u4EE5\u5C06\u6587\u672C\u4F4D\u7F6E\u8C03\u6574\u5230\u590D\u9009\u6846\u5DE6\u4FA7\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">label-position</span>=<span class="hljs-string">"left"</span>></span>\u590D\u9009\u6846<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="jin-yong-wen-ben-dian-ji" tabindex="-1">\u7981\u7528\u6587\u672C\u70B9\u51FB</h3>\n<p>\u8BBE\u7F6E <code>label-disabled</code> \u5C5E\u6027\u540E\uFF0C\u70B9\u51FB\u56FE\u6807\u4EE5\u5916\u7684\u5185\u5BB9\u4E0D\u4F1A\u89E6\u53D1\u590D\u9009\u6846\u5207\u6362\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">label-disabled</span>></span>\u590D\u9009\u6846<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="fu-xuan-kuang-zu" tabindex="-1">\u590D\u9009\u6846\u7EC4</h3>\n<p>\u590D\u9009\u6846\u53EF\u4EE5\u4E0E\u590D\u9009\u6846\u7EC4\u4E00\u8D77\u4F7F\u7528\uFF0C\u590D\u9009\u6846\u7EC4\u901A\u8FC7 <code>v-model</code> \u6570\u7EC4\u7ED1\u5B9A\u590D\u9009\u6846\u7684\u52FE\u9009\u72B6\u6001\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox-group</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"a"</span>></span>\u590D\u9009\u6846 a<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"b"</span>></span>\u590D\u9009\u6846 b<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox-group</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> checked = <span class="hljs-title function_">ref</span>([<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>]);\n <span class="hljs-keyword">return</span> { checked };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="shui-ping-pai-lie" tabindex="-1">\u6C34\u5E73\u6392\u5217</h3>\n<p>\u5C06 <code>direction</code> \u5C5E\u6027\u8BBE\u7F6E\u4E3A <code>horizontal</code> \u540E\uFF0C\u590D\u9009\u6846\u7EC4\u4F1A\u53D8\u6210\u6C34\u5E73\u6392\u5217\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox-group</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">direction</span>=<span class="hljs-string">"horizontal"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"a"</span>></span>\u590D\u9009\u6846 a<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"b"</span>></span>\u590D\u9009\u6846 b<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox-group</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> checked = <span class="hljs-title function_">ref</span>([]);\n <span class="hljs-keyword">return</span> { checked };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="xian-zhi-zui-da-ke-xuan-shu" tabindex="-1">\u9650\u5236\u6700\u5927\u53EF\u9009\u6570</h3>\n<p>\u901A\u8FC7 <code>max</code> \u5C5E\u6027\u53EF\u4EE5\u9650\u5236\u590D\u9009\u6846\u7EC4\u7684\u6700\u5927\u53EF\u9009\u6570\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox-group</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">:max</span>=<span class="hljs-string">"2"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"a"</span>></span>\u590D\u9009\u6846 a<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"b"</span>></span>\u590D\u9009\u6846 b<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"c"</span>></span>\u590D\u9009\u6846 c<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox-group</span>></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="quan-xuan-yu-fan-xuan" tabindex="-1">\u5168\u9009\u4E0E\u53CD\u9009</h3>\n<p>\u901A\u8FC7 <code>CheckboxGroup</code> \u5B9E\u4F8B\u4E0A\u7684 <code>toggleAll</code> \u65B9\u6CD5\u53EF\u4EE5\u5B9E\u73B0\u5168\u9009\u4E0E\u53CD\u9009\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox-group</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">"checkboxGroup"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"a"</span>></span>\u590D\u9009\u6846 a<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"b"</span>></span>\u590D\u9009\u6846 b<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"c"</span>></span>\u590D\u9009\u6846 c<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox-group</span>></span>\n\n<span class="hljs-tag"><<span class="hljs-name">van-button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"primary"</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"checkAll"</span>></span>\u5168\u9009<span class="hljs-tag"></<span class="hljs-name">van-button</span>></span>\n<span class="hljs-tag"><<span class="hljs-name">van-button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"primary"</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"toggleAll"</span>></span>\u53CD\u9009<span class="hljs-tag"></<span class="hljs-name">van-button</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> checked = <span class="hljs-title function_">ref</span>([]);\n <span class="hljs-keyword">const</span> checkboxGroup = <span class="hljs-title function_">ref</span>(<span class="hljs-literal">null</span>);\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">checkAll</span> = (<span class="hljs-params"></span>) => {\n checkboxGroup.<span class="hljs-property">value</span>.<span class="hljs-title function_">toggleAll</span>(<span class="hljs-literal">true</span>);\n }\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">toggleAll</span> = (<span class="hljs-params"></span>) => {\n checkboxGroup.<span class="hljs-property">value</span>.<span class="hljs-title function_">toggleAll</span>();\n },\n\n <span class="hljs-keyword">return</span> {\n checked,\n checkAll,\n toggleAll,\n checkboxGroup,\n };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="da-pei-dan-yuan-ge-zu-jian-shi-yong" tabindex="-1">\u642D\u914D\u5355\u5143\u683C\u7EC4\u4EF6\u4F7F\u7528</h3>\n<p>\u642D\u914D\u5355\u5143\u683C\u7EC4\u4EF6\u4F7F\u7528\u65F6\uFF0C\u9700\u8981\u518D\u5F15\u5165 <code>Cell</code> \u548C <code>CellGroup</code> \u7EC4\u4EF6\uFF0C\u5E76\u901A\u8FC7 <code>Checkbox</code> \u5B9E\u4F8B\u4E0A\u7684 toggle \u65B9\u6CD5\u89E6\u53D1\u5207\u6362\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox-group</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checked"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-cell-group</span> <span class="hljs-attr">inset</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-cell</span>\n <span class="hljs-attr">v-for</span>=<span class="hljs-string">"(item, index) in list"</span>\n <span class="hljs-attr">clickable</span>\n <span class="hljs-attr">:key</span>=<span class="hljs-string">"item"</span>\n <span class="hljs-attr">:title</span>=<span class="hljs-string">"`\u590D\u9009\u6846 ${item}`"</span>\n @<span class="hljs-attr">click</span>=<span class="hljs-string">"toggle(index)"</span>\n ></span>\n <span class="hljs-tag"><<span class="hljs-name">template</span> #<span class="hljs-attr">right-icon</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span>\n <span class="hljs-attr">:name</span>=<span class="hljs-string">"item"</span>\n <span class="hljs-attr">:ref</span>=<span class="hljs-string">"el => checkboxRefs[index] = el"</span>\n @<span class="hljs-attr">click.stop</span>\n /></span>\n <span class="hljs-tag"></<span class="hljs-name">template</span>></span>\n <span class="hljs-tag"></<span class="hljs-name">van-cell</span>></span>\n <span class="hljs-tag"></<span class="hljs-name">van-cell-group</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox-group</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref, onBeforeUpdate } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> checked = <span class="hljs-title function_">ref</span>([]);\n <span class="hljs-keyword">const</span> checkboxRefs = <span class="hljs-title function_">ref</span>([]);\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">toggle</span> = (<span class="hljs-params">index</span>) => {\n checkboxRefs.<span class="hljs-property">value</span>[index].<span class="hljs-title function_">toggle</span>();\n };\n\n <span class="hljs-title function_">onBeforeUpdate</span>(<span class="hljs-function">() =></span> {\n checkboxRefs.<span class="hljs-property">value</span> = [];\n });\n\n <span class="hljs-keyword">return</span> {\n <span class="hljs-attr">list</span>: [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>],\n toggle,\n checked,\n checkboxRefs,\n };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="bu-que-ding-zhuang-tai" tabindex="-1">\u4E0D\u786E\u5B9A\u72B6\u6001</h3>\n<p>\u901A\u8FC7 <code>indeterminate</code> \u8BBE\u7F6E\u590D\u9009\u6846\u662F\u5426\u4E3A\u4E0D\u786E\u5B9A\u72B6\u6001\u3002</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-checkbox</span>\n <span class="hljs-attr">v-model</span>=<span class="hljs-string">"isCheckAll"</span>\n <span class="hljs-attr">:indeterminate</span>=<span class="hljs-string">"isIndeterminate"</span>\n @<span class="hljs-attr">change</span>=<span class="hljs-string">"checkAllChange"</span>\n></span>\n \u5168\u9009\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n\n<span class="hljs-tag"><<span class="hljs-name">van-checkbox-group</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"checkedResult"</span> @<span class="hljs-attr">change</span>=<span class="hljs-string">"checkedResultChange"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-checkbox</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">"item in list"</span> <span class="hljs-attr">:key</span>=<span class="hljs-string">"item"</span> <span class="hljs-attr">:name</span>=<span class="hljs-string">"item"</span>></span>\n \u590D\u9009\u6846 {{ item }}\n <span class="hljs-tag"></<span class="hljs-name">van-checkbox</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-checkbox-group</span>></span>\n</code></pre>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">const</span> list = [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>, <span class="hljs-string">'d'</span>]\n\n <span class="hljs-keyword">const</span> isCheckAll = <span class="hljs-title function_">ref</span>(<span class="hljs-literal">false</span>);\n <span class="hljs-keyword">const</span> checkedResult = <span class="hljs-title function_">ref</span>([<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'d'</span>]);\n <span class="hljs-keyword">const</span> isIndeterminate = <span class="hljs-title function_">ref</span>(<span class="hljs-literal">true</span>);\n\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">checkAllChange</span> = (<span class="hljs-params">val: boolean</span>) => {\n checkedResult.<span class="hljs-property">value</span> = val ? list : []\n isIndeterminate.<span class="hljs-property">value</span> = <span class="hljs-literal">false</span>\n }\n\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">checkedResultChange</span> = (<span class="hljs-params">value: string[]</span>) => {\n <span class="hljs-keyword">const</span> checkedCount = value.<span class="hljs-property">length</span>\n isCheckAll.<span class="hljs-property">value</span> = checkedCount === list.<span class="hljs-property">length</span>\n isIndeterminate.<span class="hljs-property">value</span> = checkedCount > <span class="hljs-number">0</span> && checkedCount < list.<span class="hljs-property">length</span>\n }\n\n <span class="hljs-keyword">return</span> {\n list,\n isCheckAll,\n checkedResult,\n checkAllChange,\n isIndeterminate,\n checkedResultChange\n };\n },\n};\n</code></pre>\n</div><h2 id="api" tabindex="-1">API</h2>\n<div class="van-doc-card"><h3 id="checkbox-props" tabindex="-1">Checkbox Props</h3>\n<table>\n<thead>\n<tr>\n<th>\u53C2\u6570</th>\n<th>\u8BF4\u660E</th>\n<th>\u7C7B\u578B</th>\n<th>\u9ED8\u8BA4\u503C</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>v-model</td>\n<td>\u662F\u5426\u4E3A\u9009\u4E2D\u72B6\u6001</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>name</td>\n<td>\u6807\u8BC6\u7B26\uFF0C\u901A\u5E38\u4E3A\u4E00\u4E2A\u552F\u4E00\u7684\u5B57\u7B26\u4E32\u6216\u6570\u5B57</td>\n<td><em>any</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>shape</td>\n<td>\u5F62\u72B6\uFF0C\u53EF\u9009\u503C\u4E3A <code>square</code></td>\n<td><em>string</em></td>\n<td><code>round</code></td>\n</tr>\n<tr>\n<td>disabled</td>\n<td>\u662F\u5426\u7981\u7528\u590D\u9009\u6846</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>label-disabled</td>\n<td>\u662F\u5426\u7981\u7528\u590D\u9009\u6846\u6587\u672C\u70B9\u51FB</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>label-position</td>\n<td>\u6587\u672C\u4F4D\u7F6E\uFF0C\u53EF\u9009\u503C\u4E3A <code>left</code></td>\n<td><em>string</em></td>\n<td><code>right</code></td>\n</tr>\n<tr>\n<td>icon-size</td>\n<td>\u56FE\u6807\u5927\u5C0F\uFF0C\u9ED8\u8BA4\u5355\u4F4D\u4E3A <code>px</code></td>\n<td><em>number | string</em></td>\n<td><code>20px</code></td>\n</tr>\n<tr>\n<td>checked-color</td>\n<td>\u9009\u4E2D\u72B6\u6001\u989C\u8272</td>\n<td><em>string</em></td>\n<td><code>#1989fa</code></td>\n</tr>\n<tr>\n<td>bind-group</td>\n<td>\u662F\u5426\u4E0E\u590D\u9009\u6846\u7EC4\u7ED1\u5B9A</td>\n<td><em>boolean</em></td>\n<td><code>true</code></td>\n</tr>\n<tr>\n<td>indeterminate</td>\n<td>\u662F\u5426\u4E3A\u4E0D\u786E\u5B9A\u72B6\u6001</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="checkboxgroup-props" tabindex="-1">CheckboxGroup Props</h3>\n<table>\n<thead>\n<tr>\n<th>\u53C2\u6570</th>\n<th>\u8BF4\u660E</th>\n<th>\u7C7B\u578B</th>\n<th>\u9ED8\u8BA4\u503C</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>v-model</td>\n<td>\u6240\u6709\u9009\u4E2D\u9879\u7684\u6807\u8BC6\u7B26</td>\n<td><em>any[]</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>disabled</td>\n<td>\u662F\u5426\u7981\u7528\u6240\u6709\u590D\u9009\u6846</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>max</td>\n<td>\u6700\u5927\u53EF\u9009\u6570\uFF0C<code>0</code> \u4E3A\u65E0\u9650\u5236</td>\n<td><em>number | string</em></td>\n<td><code>0</code></td>\n</tr>\n<tr>\n<td>direction</td>\n<td>\u6392\u5217\u65B9\u5411\uFF0C\u53EF\u9009\u503C\u4E3A <code>horizontal</code></td>\n<td><em>string</em></td>\n<td><code>vertical</code></td>\n</tr>\n<tr>\n<td>icon-size</td>\n<td>\u6240\u6709\u590D\u9009\u6846\u7684\u56FE\u6807\u5927\u5C0F\uFF0C\u9ED8\u8BA4\u5355\u4F4D\u4E3A <code>px</code></td>\n<td><em>number | string</em></td>\n<td><code>20px</code></td>\n</tr>\n<tr>\n<td>checked-color</td>\n<td>\u6240\u6709\u590D\u9009\u6846\u7684\u9009\u4E2D\u72B6\u6001\u989C\u8272</td>\n<td><em>string</em></td>\n<td><code>#1989fa</code></td>\n</tr>\n<tr>\n<td>shape <code>v4.6.3</code></td>\n<td>\u5F62\u72B6\uFF0C\u53EF\u9009\u503C\u4E3A <code>square</code></td>\n<td><em>string</em></td>\n<td><code>round</code></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="checkbox-events" tabindex="-1">Checkbox Events</h3>\n<table>\n<thead>\n<tr>\n<th>\u4E8B\u4EF6\u540D</th>\n<th>\u8BF4\u660E</th>\n<th>\u56DE\u8C03\u53C2\u6570</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>change</td>\n<td>\u5F53\u7ED1\u5B9A\u503C\u53D8\u5316\u65F6\u89E6\u53D1\u7684\u4E8B\u4EF6</td>\n<td><em>checked: boolean</em></td>\n</tr>\n<tr>\n<td>click</td>\n<td>\u70B9\u51FB\u590D\u9009\u6846\u65F6\u89E6\u53D1</td>\n<td><em>event: MouseEvent</em></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="checkboxgroup-events" tabindex="-1">CheckboxGroup Events</h3>\n<table>\n<thead>\n<tr>\n<th>\u4E8B\u4EF6\u540D</th>\n<th>\u8BF4\u660E</th>\n<th>\u56DE\u8C03\u53C2\u6570</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>change</td>\n<td>\u5F53\u7ED1\u5B9A\u503C\u53D8\u5316\u65F6\u89E6\u53D1\u7684\u4E8B\u4EF6</td>\n<td><em>names: any[]</em></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="checkbox-slots" tabindex="-1">Checkbox Slots</h3>\n<table>\n<thead>\n<tr>\n<th>\u540D\u79F0</th>\n<th>\u8BF4\u660E</th>\n<th>\u53C2\u6570</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>default</td>\n<td>\u81EA\u5B9A\u4E49\u6587\u672C</td>\n<td><em>{ checked: boolean, disabled: boolean }</em></td>\n</tr>\n<tr>\n<td>icon</td>\n<td>\u81EA\u5B9A\u4E49\u56FE\u6807</td>\n<td><em>{ checked: boolean, disabled: boolean }</em></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="checkboxgroup-fang-fa" tabindex="-1">CheckboxGroup \u65B9\u6CD5</h3>\n<p>\u901A\u8FC7 ref \u53EF\u4EE5\u83B7\u53D6\u5230 CheckboxGroup \u5B9E\u4F8B\u5E76\u8C03\u7528\u5B9E\u4F8B\u65B9\u6CD5\uFF0C\u8BE6\u89C1<a href="#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa" target="_blank">\u7EC4\u4EF6\u5B9E\u4F8B\u65B9\u6CD5</a>\u3002</p>\n<table>\n<thead>\n<tr>\n<th>\u65B9\u6CD5\u540D</th>\n<th>\u8BF4\u660E</th>\n<th>\u53C2\u6570</th>\n<th>\u8FD4\u56DE\u503C</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>toggleAll</td>\n<td>\u5207\u6362\u6240\u6709\u590D\u9009\u6846\uFF0C\u4F20 <code>true</code> \u4E3A\u9009\u4E2D\uFF0C<code>false</code> \u4E3A\u53D6\u6D88\u9009\u4E2D\uFF0C\u4E0D\u4F20\u53C2\u4E3A\u53D6\u53CD</td>\n<td><em>options?: boolean | object</em></td>\n<td>-</td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="toggleall-fang-fa-shi-li" tabindex="-1">toggleAll \u65B9\u6CD5\u793A\u4F8B</h3>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n<span class="hljs-keyword">import</span> type { <span class="hljs-title class_">CheckboxGroupInstance</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</span>;\n\n<span class="hljs-keyword">const</span> checkboxGroupRef = ref<<span class="hljs-title class_">CheckboxGroupInstance</span>>();\n\n<span class="hljs-comment">// \u5168\u90E8\u53CD\u9009</span>\ncheckboxGroupRef?.<span class="hljs-property">value</span>.<span class="hljs-title function_">toggleAll</span>();\n<span class="hljs-comment">// \u5168\u90E8\u9009\u4E2D</span>\ncheckboxGroupRef?.<span class="hljs-property">value</span>.<span class="hljs-title function_">toggleAll</span>(<span class="hljs-literal">true</span>);\n<span class="hljs-comment">// \u5168\u90E8\u53D6\u6D88</span>\ncheckboxGroupRef?.<span class="hljs-property">value</span>.<span class="hljs-title function_">toggleAll</span>(<span class="hljs-literal">false</span>);\n\n<span class="hljs-comment">// \u5168\u90E8\u53CD\u9009\uFF0C\u5E76\u8DF3\u8FC7\u7981\u7528\u7684\u590D\u9009\u6846</span>\ncheckboxGroupRef?.<span class="hljs-property">value</span>.<span class="hljs-title function_">toggleAll</span>({\n <span class="hljs-attr">skipDisabled</span>: <span class="hljs-literal">true</span>,\n});\n<span class="hljs-comment">// \u5168\u90E8\u9009\u4E2D\uFF0C\u5E76\u8DF3\u8FC7\u7981\u7528\u7684\u590D\u9009\u6846</span>\ncheckboxGroupRef?.<span class="hljs-property">value</span>.<span class="hljs-title function_">toggleAll</span>({\n <span class="hljs-attr">checked</span>: <span class="hljs-literal">true</span>,\n <span class="hljs-attr">skipDisabled</span>: <span class="hljs-literal">true</span>,\n});\n</code></pre>\n</div><div class="van-doc-card"><h3 id="checkbox-fang-fa" tabindex="-1">Checkbox \u65B9\u6CD5</h3>\n<p>\u901A\u8FC7 ref \u53EF\u4EE5\u83B7\u53D6\u5230 Checkbox \u5B9E\u4F8B\u5E76\u8C03\u7528\u5B9E\u4F8B\u65B9\u6CD5\uFF0C\u8BE6\u89C1<a href="#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa" target="_blank">\u7EC4\u4EF6\u5B9E\u4F8B\u65B9\u6CD5</a>\u3002</p>\n<table>\n<thead>\n<tr>\n<th>\u65B9\u6CD5\u540D</th>\n<th>\u8BF4\u660E</th>\n<th>\u53C2\u6570</th>\n<th>\u8FD4\u56DE\u503C</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>toggle</td>\n<td>\u5207\u6362\u9009\u4E2D\u72B6\u6001\uFF0C\u4F20 <code>true</code> \u4E3A\u9009\u4E2D\uFF0C<code>false</code> \u4E3A\u53D6\u6D88\u9009\u4E2D\uFF0C\u4E0D\u4F20\u53C2\u4E3A\u53D6\u53CD</td>\n<td><em>checked?: boolean</em></td>\n<td>-</td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="lei-xing-ding-yi" tabindex="-1">\u7C7B\u578B\u5B9A\u4E49</h3>\n<p>\u7EC4\u4EF6\u5BFC\u51FA\u4EE5\u4E0B\u7C7B\u578B\u5B9A\u4E49\uFF1A</p>\n<pre><code class="language-ts"><span class="hljs-keyword">import</span> <span class="hljs-keyword">type</span> {\n <span class="hljs-title class_">CheckboxProps</span>,\n <span class="hljs-title class_">CheckboxShape</span>,\n <span class="hljs-title class_">CheckboxInstance</span>,\n <span class="hljs-title class_">CheckboxLabelPosition</span>,\n <span class="hljs-title class_">CheckboxGroupProps</span>,\n <span class="hljs-title class_">CheckboxGroupInstance</span>,\n <span class="hljs-title class_">CheckboxGroupDirection</span>,\n <span class="hljs-title class_">CheckboxGroupToggleAllOptions</span>,\n} <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</span>;\n</code></pre>\n<p><code>CheckboxInstance</code> \u548C <code>CheckboxGroupInstance</code> \u662F\u7EC4\u4EF6\u5B9E\u4F8B\u7684\u7C7B\u578B\uFF0C\u7528\u6CD5\u5982\u4E0B\uFF1A</p>\n<pre><code class="language-ts"><span class="hljs-keyword">import</span> { ref } <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>;\n<span class="hljs-keyword">import</span> <span class="hljs-keyword">type</span> { <span class="hljs-title class_">CheckboxInstance</span>, <span class="hljs-title class_">CheckboxGroupInstance</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</span>;\n\n<span class="hljs-keyword">const</span> checkboxRef = ref<<span class="hljs-title class_">CheckboxInstance</span>>();\n<span class="hljs-keyword">const</span> checkboxGroupRef = ref<<span class="hljs-title class_">CheckboxGroupInstance</span>>();\n\ncheckboxRef.<span class="hljs-property">value</span>?.<span class="hljs-title function_">toggle</span>();\ncheckboxGroupRef.<span class="hljs-property">value</span>?.<span class="hljs-title function_">toggleAll</span>();\n</code></pre>\n</div><h2 id="zhu-ti-ding-zhi" tabindex="-1">\u4E3B\u9898\u5B9A\u5236</h2>\n<div class="van-doc-card"><h3 id="yang-shi-bian-liang" tabindex="-1">\u6837\u5F0F\u53D8\u91CF</h3>\n<p>\u7EC4\u4EF6\u63D0\u4F9B\u4E86\u4E0B\u5217 CSS \u53D8\u91CF\uFF0C\u53EF\u7528\u4E8E\u81EA\u5B9A\u4E49\u6837\u5F0F\uFF0C\u4F7F\u7528\u65B9\u6CD5\u8BF7\u53C2\u8003 <a href="#/zh-CN/config-provider" target="_blank">ConfigProvider \u7EC4\u4EF6</a>\u3002</p>\n<table>\n<thead>\n<tr>\n<th>\u540D\u79F0</th>\n<th>\u9ED8\u8BA4\u503C</th>\n<th>\u63CF\u8FF0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>--van-checkbox-size</td>\n<td><em>20px</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-border-color</td>\n<td><em>var(--van-gray-5)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-duration</td>\n<td><em>var(--van-duration-fast)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-label-margin</td>\n<td><em>var(--van-padding-xs)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-label-color</td>\n<td><em>var(--van-text-color)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-checked-icon-color</td>\n<td><em>var(--van-primary-color)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-disabled-icon-color</td>\n<td><em>var(--van-gray-5)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-disabled-label-color</td>\n<td><em>var(--van-text-color-3)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-checkbox-disabled-background</td>\n<td><em>var(--van-border-color)</em></td>\n<td>-</td>\n</tr>\n</tbody>\n</table>\n</div>'},null,8,t))}}}]); |