CARVIEW |
Select Language
HTTP/2 200
date: Sat, 19 Jul 2025 16:42:55 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"9f93c2f3ac1a77466bd305ae6c0358db"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=mLocvJv73YnU5PxgnRc5S8IiD5EbDL%2F6R5e6HhkxmkbWXRR7Zl4rW3mtJfOnpNdRxJReKngxJrHJDGBcXO6lW9B9736WvljV8pFPhzKuWu4z5S%2B9acw%2BARA%2F1fYaItyEn3bpfl%2BPyq4iryBw6CVYdiEGmcW6sttGS1ECmqM67laOEXVEoUhJSNjRnTGHjQE9OcDHHruWSJ%2BEn0KRoLnSA3W7hBtjbz5Y4RF2PSEx6ndmg7PBwGbblWaBjzSWRoKPn4tdMvOWqiL0a6XNZblXQA%3D%3D--fNwcX5hSlChPMGu8--cqhNklKd4EVGPTWWGMyGHw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.604717949.1752943375; Path=/; Domain=github.com; Expires=Sun, 19 Jul 2026 16:42:55 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 19 Jul 2026 16:42:55 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: AA04:2BEE38:6AE3A2:85BD84:687BCB0F
Usage_zh · hiyali/vue-smooth-picker Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Usage_zh
Leilei Chui edited this page Dec 3, 2019
·
9 revisions
npm
npm i -S vue-smooth-picker
或者 yarn
yarn add vue-smooth-picker
import 'vue-smooth-picker/dist/css/style.css'
import SmoothPicker from 'vue-smooth-picker'
Vue.use(SmoothPicker)
在你的 Vue 模板里
<template>
...
<smooth-picker ref="smoothPicker" :data="data" :change="change" />
...
</template>
...
data () {
return {
data: [
{
currentIndex: 0,
flex: 3,
list: [
'Plan A - free', 'Plan B - $50', 'Plan C - $100'
],
onClick: this.clickOnPlan,
textAlign: 'center',
className: 'row-group'
},
{
divider: true,
flex: 1,
text: 'product',
textAlign: 'center',
className: 'divider'
},
{
currentIndex: 2,
flex: 3,
list: [
'1 * A item', '2 * A items', '3 * A items', '4 * A items', '5 * A items'
],
onClick: this.clickOnProduct,
textAlign: 'center',
className: 'item-group'
}
]
}
},
...
...
methods: {
change (gIndex, iIndex) {
console.info('group:', gIndex, ' index:', iIndex)
}
}
...
名 | 类型 | 默认值 | 解释 |
---|---|---|---|
change |
Function |
(gIndex, iIndex) => {} | 数据变更后的回调,传两参数,分别是 排索引 gIndex 和 排值索引 iIndex
|
data |
Array |
[] | 初始数据 |
data[i].currentIndex |
Number |
0 | 排值的默认索引 |
data[i].flex |
Number |
1 | 排区域在整个组件宽度种的权重 1..12
|
data[i].list |
Array |
- | 排的值数组 |
data[i].list[j] |
String or Object
|
- | 排的某个值,如果是对象可以用 value 键名 |
data[i].onClick |
Function |
- | 排的中间层被按下时的回调, 传两参数, 分别是 排索引 gIndex 和 排值索引 iIndex
|
data[i].textAlign |
String |
- | 在排内靠 左边 left 、中间 center 或者 右边 right
|
data[i].className |
String |
- | 排的自定义 css 类名 |
data[i].divider |
Boolean |
false | 如果是它的值为 true ,那么它就是分割排,并且它的 onClick list currentIndex 将不管用 |
data[i].text |
String |
- | 只能在 divider 为 true 是使用 |
名 | 类型 | 解释 |
---|---|---|
setGroupData |
Function |
动态设置某排的数据 (gIndex, gData) , 例如:list 、currentIndex 等。 (见属性 data[i] ) |
getCurrentIndexList |
Function |
返回一数组 Array 类型的所有排的索引数组 (包括分割排 divider 的排索引,分割排默认排索引为 0 ) |
getGroupsRectList |
Function |
这个方法会重新收集触摸作用区域的信息,如果页面picker组件初始化的时候它的dom是不可见的状态,你可以在它可见时重新使用此方法来正常使用本组件。 |
<template>
<div class="example-page">
<!-- 3. 使用 -->
<smooth-picker ref="smoothPicker" :data="data" :change="dataChange" />
<button class="button" type="button" @click="confirm">Confirm</button>
</div>
</template>
<script>
// 1. 引入
import 'vue-smooth-picker/dist/css/style.css'
import { SmoothPicker } from 'vue-smooth-picker'
export default {
name: 'example-page',
components: {
SmoothPicker // 2. 注册组件
},
data () {
return {
data: [ // 4. 传入数据
{
currentIndex: 0,
flex: 3,
list: [
'Plan A - free', 'Plan B - $50', 'Plan C - $100'
],
onClick: this.clickOnPlan,
textAlign: 'center',
className: 'row-group'
},
{
divider: true,
flex: 1,
text: 'product',
textAlign: 'center',
className: 'divider'
},
{
currentIndex: 2,
flex: 3,
list: [
'1 * A item', '2 * A items', '3 * A items', '4 * A items', '5 * A items'
],
onClick: this.clickOnProduct,
textAlign: 'center',
className: 'item-group'
}
]
}
},
methods: {
// 5. 监听变化
dataChange (gIndex, iIndex) {
console.info('list', gIndex, iIndex)
if (gIndex === 0) {
let currentIndex = 0
let list = []
switch (iIndex) {
case 2:
list = ['C item 1', 'C item 2', 'C item 3', 'C item 4', 'C item 5', 'C item 6', 'C item 7', 'C item 8', 'C item 9']
currentIndex = 4
break
case 1:
list = ['1 * B item', '2 * B items', '3 * B items', '4 * B items', '5 * B items', '6 * B items', '7 * B items']
currentIndex = 3
break
default:
list = ['1 * A item', '2 * A items', '3 * A items', '4 * A items', '5 * A items']
currentIndex = 2
}
this.$refs.smoothPicker.setGroupData(2, Object.assign({}, this.data[2], { currentIndex, list }))
}
},
// 6. 监听中间层点击
clickOnPlan (gIndex, iIndex) {
window.alert('Clicked plan: ' + this.data[gIndex].list[iIndex])
},
clickOnProduct (gIndex, iIndex) {
window.alert('Clicked product: ' + this.data[gIndex].list[iIndex])
},
// 7. 拿到当前指定的数据索引
confirm () {
const ciList = this.$refs.smoothPicker.getCurrentIndexList()
const planDetail = this.data[0].list[ciList[0]]
const productDetail = this.data[2].list[ciList[2]]
window.alert(
'Confirmed index list: ' + ciList + '.\n' +
'Confirmed plan: ' + planDetail + '.\n' +
'Confirmed product: ' + productDetail
)
}
}
}
</script>
npm run dev # 开发
npm run build # 生产
请让我知道
You can’t perform that action at this time.