/*! 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:'
Used to select a value within a given range.
\nRegister component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Slider } from 'vant';\n\nconst app = createApp();\napp.use(Slider);\n
\n<van-slider v-model="value" @change="onChange" />\n
\nimport { ref } from 'vue';\nimport { showToast } from 'vant';\n\nexport default {\n setup() {\n const value = ref(50);\n const onChange = (value) => showToast('Current value: ' + value);\n return {\n value,\n onChange,\n };\n },\n};\n
\nAdd range
attribute to open dual thumb mode.
<van-slider v-model="value" range @change="onChange" />\n
\nimport { ref } from 'vue';\nimport { showToast } from 'vant';\n\nexport default {\n setup() {\n // value must be an Array\n const value = ref([10, 50]);\n const onChange = (value) => showToast('Current value: ' + value);\n return {\n value,\n onChange,\n };\n },\n};\n
\n<van-slider v-model="value" :min="-50" :max="50" />\n
\n<van-slider v-model="value" disabled />\n
\n<van-slider v-model="value" :step="10" />\n
\n<van-slider v-model="value" bar-height="4px" active-color="#ee0a24" />\n
\n<van-slider v-model="value">\n <template #button>\n <div class="custom-button">{{ value }}</div>\n </template>\n</van-slider>\n\n<style>\n .custom-button {\n width: 26px;\n color: #fff;\n font-size: 10px;\n line-height: 18px;\n text-align: center;\n background-color: var(--van-primary-color);\n border-radius: 100px;\n }\n</style>\n
\n<div :style="{ height: '150px' }">\n <van-slider v-model="value" vertical @change="onChange" />\n <van-slider\n v-model="value2"\n range\n vertical\n style="margin-left: 100px;"\n @change="onChange"\n />\n</div>\n
\nimport { ref } from 'vue';\nimport { showToast } from 'vant';\n\nexport default {\n setup() {\n const value = ref(50);\n const value2 = ref([10, 50]);\n const onChange = (value) => showToast('Current value: ' + value);\n return {\n value,\n value2,\n onChange,\n };\n },\n};\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
v-model | \nCurrent value | \nnumber | [number, number] | \n0 | \n
max | \nMax value | \nnumber | string | \n100 | \n
min | \nMin value | \nnumber | string | \n0 | \n
step | \nStep size | \nnumber | string | \n1 | \n
bar-height | \nHeight of bar | \nnumber | string | \n2px | \n
button-size | \nButton size | \nnumber | string | \n24px | \n
active-color | \nActive color of bar | \nstring | \n#1989fa | \n
inactive-color | \nInactive color of bar | \nstring | \n#e5e5e5 | \n
range | \nWhether to enable dual thumb mode | \nboolean | \nfalse | \n
reverse | \nWhether to reverse slider | \nboolean | \nfalse | \n
disabled | \nWhether to disable slider | \nboolean | \nfalse | \n
readonly | \nWhether to be readonly | \nboolean | \nfalse | \n
vertical | \nWhether to display slider vertically | \nboolean | \nfalse | \n
Event | \nDescription | \nArguments | \n
---|---|---|
update:model-value | \nEmitted when value is changing | \nvalue: number | \n
change | \nEmitted after value changed | \nvalue: number | \n
drag-start | \nEmitted when start dragging | \nevent: TouchEvent | \n
drag-end | \nEmitted when end dragging | \nevent: TouchEvent | \n
Name | \nDescription | \nSlotProps | \n
---|---|---|
button | \nCustom button | \n{ value: number, dragging: boolean } | \n
left-button | \nCustom left button in range mode | \n{ value: number, dragging: boolean, dragIndex?: number } | \n
right-button | \nCustom right button in range mode | \n{ value: number, dragging: boolean, dragIndex?: number } | \n
The component exports the following type definitions:
\nimport type { SliderProps } from 'vant';\n
\nThe component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
\nName | \nDefault Value | \nDescription | \n
---|---|---|
--van-slider-active-background | \nvar(--van-primary-color) | \n- | \n
--van-slider-inactive-background | \nvar(--van-gray-3) | \n- | \n
--van-slider-disabled-opacity | \nvar(--van-disabled-opacity) | \n- | \n
--van-slider-bar-height | \n2px | \n- | \n
--van-slider-button-width | \n24px | \n- | \n
--van-slider-button-height | \n24px | \n- | \n
--van-slider-button-radius | \n50% | \n- | \n
--van-slider-button-background | \nvar(--van-white) | \n- | \n
--van-slider-button-shadow | \n0 1px 2px rgba(0, 0, 0, 0.5) | \n- | \n