mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
/*! For license information please see 8796.15546f93.js.LICENSE.txt */
|
|
(self.webpackChunk=self.webpackChunk||[]).push([["8796"],{50244:function(s,n,a){"use strict";a.r(n);var t=a("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,t.wg)(),(0,t.iD)("div",{class:"van-doc-markdown-body",innerHTML:'<h1>Slider</h1>\n<div class="van-doc-card"><h3 id="intro" tabindex="-1">Intro</h3>\n<p>Used to select a value within a given range.</p>\n</div><div class="van-doc-card"><h3 id="install" tabindex="-1">Install</h3>\n<p>Register component globally via <code>app.use</code>, refer to <a href="#/en-US/advanced-usage#zu-jian-zhu-ce" target="_blank">Component Registration</a> for more registration ways.</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_">Slider</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_">Slider</span>);\n</code></pre>\n</div><h2 id="usage" tabindex="-1">Usage</h2>\n<div class="van-doc-card"><h3 id="basic-usage" tabindex="-1">Basic Usage</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span> @<span class="hljs-attr">change</span>=<span class="hljs-string">"onChange"</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<span class="hljs-keyword">import</span> { showToast } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</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> value = <span class="hljs-title function_">ref</span>(<span class="hljs-number">50</span>);\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">onChange</span> = (<span class="hljs-params">value</span>) => <span class="hljs-title function_">showToast</span>(<span class="hljs-string">'Current value: '</span> + value);\n <span class="hljs-keyword">return</span> {\n value,\n onChange,\n };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="dual-thumb" tabindex="-1">Dual thumb</h3>\n<p>Add <code>range</code> attribute to open dual thumb mode.</p>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span> <span class="hljs-attr">range</span> @<span class="hljs-attr">change</span>=<span class="hljs-string">"onChange"</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<span class="hljs-keyword">import</span> { showToast } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</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-comment">// value must be an Array</span>\n <span class="hljs-keyword">const</span> value = <span class="hljs-title function_">ref</span>([<span class="hljs-number">10</span>, <span class="hljs-number">50</span>]);\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">onChange</span> = (<span class="hljs-params">value</span>) => <span class="hljs-title function_">showToast</span>(<span class="hljs-string">'Current value: '</span> + value);\n <span class="hljs-keyword">return</span> {\n value,\n onChange,\n };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="range" tabindex="-1">Range</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span> <span class="hljs-attr">:min</span>=<span class="hljs-string">"-50"</span> <span class="hljs-attr">:max</span>=<span class="hljs-string">"50"</span> /></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="disabled" tabindex="-1">Disabled</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span> <span class="hljs-attr">disabled</span> /></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="step-size" tabindex="-1">Step size</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span> <span class="hljs-attr">:step</span>=<span class="hljs-string">"10"</span> /></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="custom-style" tabindex="-1">Custom style</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span> <span class="hljs-attr">bar-height</span>=<span class="hljs-string">"4px"</span> <span class="hljs-attr">active-color</span>=<span class="hljs-string">"#ee0a24"</span> /></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="custom-button" tabindex="-1">Custom button</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">template</span> #<span class="hljs-attr">button</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"custom-button"</span>></span>{{ value }}<span class="hljs-tag"></<span class="hljs-name">div</span>></span>\n <span class="hljs-tag"></<span class="hljs-name">template</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-slider</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">.custom-button</span> {\n <span class="hljs-attribute">width</span>: <span class="hljs-number">26px</span>;\n <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;\n <span class="hljs-attribute">font-size</span>: <span class="hljs-number">10px</span>;\n <span class="hljs-attribute">line-height</span>: <span class="hljs-number">18px</span>;\n <span class="hljs-attribute">text-align</span>: center;\n <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--van-primary-color);\n <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">100px</span>;\n }\n</span><span class="hljs-tag"></<span class="hljs-name">style</span>></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="vertical" tabindex="-1">Vertical</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">:style</span>=<span class="hljs-string">"{ height: '150px' }"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-slider</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value"</span> <span class="hljs-attr">vertical</span> @<span class="hljs-attr">change</span>=<span class="hljs-string">"onChange"</span> /></span>\n <span class="hljs-tag"><<span class="hljs-name">van-slider</span>\n <span class="hljs-attr">v-model</span>=<span class="hljs-string">"value2"</span>\n <span class="hljs-attr">range</span>\n <span class="hljs-attr">vertical</span>\n <span class="hljs-attr">style</span>=<span class="hljs-string">"margin-left: 100px;"</span>\n @<span class="hljs-attr">change</span>=<span class="hljs-string">"onChange"</span>\n /></span>\n<span class="hljs-tag"></<span class="hljs-name">div</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<span class="hljs-keyword">import</span> { showToast } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</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> value = <span class="hljs-title function_">ref</span>(<span class="hljs-number">50</span>);\n <span class="hljs-keyword">const</span> value2 = <span class="hljs-title function_">ref</span>([<span class="hljs-number">10</span>, <span class="hljs-number">50</span>]);\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">onChange</span> = (<span class="hljs-params">value</span>) => <span class="hljs-title function_">showToast</span>(<span class="hljs-string">'Current value: '</span> + value);\n <span class="hljs-keyword">return</span> {\n value,\n value2,\n onChange,\n };\n },\n};\n</code></pre>\n</div><h2 id="api" tabindex="-1">API</h2>\n<div class="van-doc-card"><h3 id="props" tabindex="-1">Props</h3>\n<table>\n<thead>\n<tr>\n<th>Attribute</th>\n<th>Description</th>\n<th>Type</th>\n<th>Default</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>v-model</td>\n<td>Current value</td>\n<td><em>number | [number, number]</em></td>\n<td><code>0</code></td>\n</tr>\n<tr>\n<td>max</td>\n<td>Max value</td>\n<td><em>number | string</em></td>\n<td><code>100</code></td>\n</tr>\n<tr>\n<td>min</td>\n<td>Min value</td>\n<td><em>number | string</em></td>\n<td><code>0</code></td>\n</tr>\n<tr>\n<td>step</td>\n<td>Step size</td>\n<td><em>number | string</em></td>\n<td><code>1</code></td>\n</tr>\n<tr>\n<td>bar-height</td>\n<td>Height of bar</td>\n<td><em>number | string</em></td>\n<td><code>2px</code></td>\n</tr>\n<tr>\n<td>button-size</td>\n<td>Button size</td>\n<td><em>number | string</em></td>\n<td><code>24px</code></td>\n</tr>\n<tr>\n<td>active-color</td>\n<td>Active color of bar</td>\n<td><em>string</em></td>\n<td><code>#1989fa</code></td>\n</tr>\n<tr>\n<td>inactive-color</td>\n<td>Inactive color of bar</td>\n<td><em>string</em></td>\n<td><code>#e5e5e5</code></td>\n</tr>\n<tr>\n<td>range</td>\n<td>Whether to enable dual thumb mode</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>reverse</td>\n<td>Whether to reverse slider</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>disabled</td>\n<td>Whether to disable slider</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>readonly</td>\n<td>Whether to be readonly</td>\n<td><em>boolean</em></td>\n<td><code>false</code></td>\n</tr>\n<tr>\n<td>vertical</td>\n<td>Whether to display slider vertically</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="events" tabindex="-1">Events</h3>\n<table>\n<thead>\n<tr>\n<th>Event</th>\n<th>Description</th>\n<th>Arguments</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>update:model-value</td>\n<td>Emitted when value is changing</td>\n<td><em>value: number</em></td>\n</tr>\n<tr>\n<td>change</td>\n<td>Emitted after value changed</td>\n<td><em>value: number</em></td>\n</tr>\n<tr>\n<td>drag-start</td>\n<td>Emitted when start dragging</td>\n<td><em>event: TouchEvent</em></td>\n</tr>\n<tr>\n<td>drag-end</td>\n<td>Emitted when end dragging</td>\n<td><em>event: TouchEvent</em></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="slots" tabindex="-1">Slots</h3>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Description</th>\n<th>SlotProps</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>button</td>\n<td>Custom button</td>\n<td><em>{ value: number, dragging: boolean }</em></td>\n</tr>\n<tr>\n<td>left-button</td>\n<td>Custom left button in range mode</td>\n<td><em>{ value: number, dragging: boolean, dragIndex?: number }</em></td>\n</tr>\n<tr>\n<td>right-button</td>\n<td>Custom right button in range mode</td>\n<td><em>{ value: number, dragging: boolean, dragIndex?: number }</em></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="types" tabindex="-1">Types</h3>\n<p>The component exports the following type definitions:</p>\n<pre><code class="language-ts"><span class="hljs-keyword">import</span> <span class="hljs-keyword">type</span> { <span class="hljs-title class_">SliderProps</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</span>;\n</code></pre>\n</div><h2 id="theming" tabindex="-1">Theming</h2>\n<div class="van-doc-card"><h3 id="css-variables" tabindex="-1">CSS Variables</h3>\n<p>The component provides the following CSS variables, which can be used to customize styles. Please refer to <a href="#/en-US/config-provider" target="_blank">ConfigProvider component</a>.</p>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Default Value</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>--van-slider-active-background</td>\n<td><em>var(--van-primary-color)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-inactive-background</td>\n<td><em>var(--van-gray-3)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-disabled-opacity</td>\n<td><em>var(--van-disabled-opacity)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-bar-height</td>\n<td><em>2px</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-button-width</td>\n<td><em>24px</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-button-height</td>\n<td><em>24px</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-button-radius</td>\n<td><em>50%</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-button-background</td>\n<td><em>var(--van-white)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-slider-button-shadow</td>\n<td><em>0 1px 2px rgba(0, 0, 0, 0.5)</em></td>\n<td>-</td>\n</tr>\n</tbody>\n</table>\n</div>'},null,8,e))}}}]); |