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 2512.7c851ddb.js.LICENSE.txt */
|
|
(self.webpackChunk=self.webpackChunk||[]).push([["2512"],{1560:function(s,n,a){"use strict";a.r(n);var t=a("80681");let l=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,t.wg)(),(0,t.iD)("div",{class:"van-doc-markdown-body",innerHTML:'<h1>CountDown</h1>\n<div class="van-doc-card"><h3 id="intro" tabindex="-1">Intro</h3>\n<p>Used to display the countdown value in real time, and precision supports milliseconds.</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_">CountDown</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_">CountDown</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-count-down</span> <span class="hljs-attr">:time</span>=<span class="hljs-string">"time"</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> time = <span class="hljs-title function_">ref</span>(<span class="hljs-number">30</span> * <span class="hljs-number">60</span> * <span class="hljs-number">60</span> * <span class="hljs-number">1000</span>);\n <span class="hljs-keyword">return</span> { time };\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="custom-format" tabindex="-1">Custom Format</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-count-down</span> <span class="hljs-attr">:time</span>=<span class="hljs-string">"time"</span> <span class="hljs-attr">format</span>=<span class="hljs-string">"DD Day, HH:mm:ss"</span> /></span>\n</code></pre>\n</div><div class="van-doc-card"><h3 id="millisecond" tabindex="-1">Millisecond</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-count-down</span> <span class="hljs-attr">millisecond</span> <span class="hljs-attr">:time</span>=<span class="hljs-string">"time"</span> <span class="hljs-attr">format</span>=<span class="hljs-string">"HH:mm:ss:SS"</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-count-down</span> <span class="hljs-attr">:time</span>=<span class="hljs-string">"time"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">template</span> #<span class="hljs-attr">default</span>=<span class="hljs-string">"timeData"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"block"</span>></span>{{ timeData.hours }}<span class="hljs-tag"></<span class="hljs-name">span</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"colon"</span>></span>:<span class="hljs-tag"></<span class="hljs-name">span</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"block"</span>></span>{{ timeData.minutes }}<span class="hljs-tag"></<span class="hljs-name">span</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"colon"</span>></span>:<span class="hljs-tag"></<span class="hljs-name">span</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"block"</span>></span>{{ timeData.seconds }}<span class="hljs-tag"></<span class="hljs-name">span</span>></span>\n <span class="hljs-tag"></<span class="hljs-name">template</span>></span>\n<span class="hljs-tag"></<span class="hljs-name">van-count-down</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">.colon</span> {\n <span class="hljs-attribute">display</span>: inline-block;\n <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span>;\n <span class="hljs-attribute">color</span>: <span class="hljs-number">#1989fa</span>;\n }\n <span class="hljs-selector-class">.block</span> {\n <span class="hljs-attribute">display</span>: inline-block;\n <span class="hljs-attribute">width</span>: <span class="hljs-number">22px</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">12px</span>;\n <span class="hljs-attribute">text-align</span>: center;\n <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#1989fa</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="manual-control" tabindex="-1">Manual Control</h3>\n<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">van-count-down</span>\n <span class="hljs-attr">ref</span>=<span class="hljs-string">"countDown"</span>\n <span class="hljs-attr">millisecond</span>\n <span class="hljs-attr">:time</span>=<span class="hljs-string">"3000"</span>\n <span class="hljs-attr">:auto-start</span>=<span class="hljs-string">"false"</span>\n <span class="hljs-attr">format</span>=<span class="hljs-string">"ss:SSS"</span>\n @<span class="hljs-attr">finish</span>=<span class="hljs-string">"onFinish"</span>\n/></span>\n<span class="hljs-tag"><<span class="hljs-name">van-grid</span> <span class="hljs-attr">clickable</span> <span class="hljs-attr">:column-num</span>=<span class="hljs-string">"3"</span>></span>\n <span class="hljs-tag"><<span class="hljs-name">van-grid-item</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"Start"</span> <span class="hljs-attr">icon</span>=<span class="hljs-string">"play-circle-o"</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"start"</span> /></span>\n <span class="hljs-tag"><<span class="hljs-name">van-grid-item</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"Pause"</span> <span class="hljs-attr">icon</span>=<span class="hljs-string">"pause-circle-o"</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"pause"</span> /></span>\n <span class="hljs-tag"><<span class="hljs-name">van-grid-item</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"Reset"</span> <span class="hljs-attr">icon</span>=<span class="hljs-string">"replay"</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"reset"</span> /></span>\n<span class="hljs-tag"></<span class="hljs-name">van-grid</span>></span>\n</code></pre>\n<pre><code class="language-js"><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> countDown = <span class="hljs-title function_">ref</span>(<span class="hljs-literal">null</span>);\n\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">start</span> = (<span class="hljs-params"></span>) => {\n countDown.<span class="hljs-property">value</span>.<span class="hljs-title function_">start</span>();\n };\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">pause</span> = (<span class="hljs-params"></span>) => {\n countDown.<span class="hljs-property">value</span>.<span class="hljs-title function_">pause</span>();\n };\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">reset</span> = (<span class="hljs-params"></span>) => {\n countDown.<span class="hljs-property">value</span>.<span class="hljs-title function_">reset</span>();\n };\n <span class="hljs-keyword">const</span> <span class="hljs-title function_">onFinish</span> = (<span class="hljs-params"></span>) => <span class="hljs-title function_">showToast</span>(<span class="hljs-string">'Finished'</span>);\n\n <span class="hljs-keyword">return</span> {\n start,\n pause,\n reset,\n onFinish,\n countDown,\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>time</td>\n<td>Total time, unit milliseconds</td>\n<td><em>number | string</em></td>\n<td><code>0</code></td>\n</tr>\n<tr>\n<td>format</td>\n<td>Time format</td>\n<td><em>string</em></td>\n<td><code>HH:mm:ss</code></td>\n</tr>\n<tr>\n<td>auto-start</td>\n<td>Whether to auto start count down</td>\n<td><em>boolean</em></td>\n<td><code>true</code></td>\n</tr>\n<tr>\n<td>millisecond</td>\n<td>Whether to enable millisecond render</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="available-formats" tabindex="-1">Available formats</h3>\n<table>\n<thead>\n<tr>\n<th>Format</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>DD</td>\n<td>Day</td>\n</tr>\n<tr>\n<td>HH</td>\n<td>Hour</td>\n</tr>\n<tr>\n<td>mm</td>\n<td>Minute</td>\n</tr>\n<tr>\n<td>ss</td>\n<td>Second</td>\n</tr>\n<tr>\n<td>S</td>\n<td>Millisecond, 1-digit</td>\n</tr>\n<tr>\n<td>SS</td>\n<td>Millisecond, 2-digits</td>\n</tr>\n<tr>\n<td>SSS</td>\n<td>Millisecond, 3-digits</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>finish</td>\n<td>Emitted when count down finished</td>\n<td>-</td>\n</tr>\n<tr>\n<td>change</td>\n<td>Emitted when count down changed</td>\n<td><em>currentTime: CurrentTime</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>default</td>\n<td>Custom Content</td>\n<td><em>currentTime: CurrentTime</em></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="currenttime-structure" tabindex="-1">CurrentTime Structure</h3>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Description</th>\n<th>Type</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>total</td>\n<td>Total time, unit milliseconds</td>\n<td><em>number</em></td>\n</tr>\n<tr>\n<td>days</td>\n<td>Remain days</td>\n<td><em>number</em></td>\n</tr>\n<tr>\n<td>hours</td>\n<td>Remain hours</td>\n<td><em>number</em></td>\n</tr>\n<tr>\n<td>minutes</td>\n<td>Remain minutes</td>\n<td><em>number</em></td>\n</tr>\n<tr>\n<td>seconds</td>\n<td>Remain seconds</td>\n<td><em>number</em></td>\n</tr>\n<tr>\n<td>milliseconds</td>\n<td>Remain milliseconds</td>\n<td><em>number</em></td>\n</tr>\n</tbody>\n</table>\n</div><div class="van-doc-card"><h3 id="methods" tabindex="-1">Methods</h3>\n<p>Use <a href="https://vuejs.org/guide/essentials/template-refs.html" target="_blank">ref</a> to get CountDown instance and call instance methods.</p>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Description</th>\n<th>Attribute</th>\n<th>Return value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>start</td>\n<td>Start count down</td>\n<td>-</td>\n<td>-</td>\n</tr>\n<tr>\n<td>pause</td>\n<td>Pause count down</td>\n<td>-</td>\n<td>-</td>\n</tr>\n<tr>\n<td>reset</td>\n<td>Reset count down</td>\n<td>-</td>\n<td>-</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> {\n <span class="hljs-title class_">CountDownProps</span>,\n <span class="hljs-title class_">CountDownInstance</span>,\n <span class="hljs-title class_">CountDownCurrentTime</span>,\n} <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</span>;\n</code></pre>\n<p><code>CountDownInstance</code> is the type of component instance:</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_">CountDownInstance</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'vant'</span>;\n\n<span class="hljs-keyword">const</span> countDownRef = ref<<span class="hljs-title class_">CountDownInstance</span>>();\n\ncountDownRef.<span class="hljs-property">value</span>?.<span class="hljs-title function_">start</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-count-down-text-color</td>\n<td><em>var(--van-text-color)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-count-down-font-size</td>\n<td><em>var(--van-font-size-md)</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>--van-count-down-line-height</td>\n<td><em>var(--van-line-height-md)</em></td>\n<td>-</td>\n</tr>\n</tbody>\n</table>\n</div>'},null,8,l))}}}]); |