npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cascading-picker

v0.2.2

Published

CascadingPicker for Vue 2

Downloads

24

Readme

CascadingPicker

Description: 基于vue2的三级联动选择器,支持自定义数据,默认提供地址三级联动数据

Author: Alan Chen

Contact: [email protected]

Version: 0.2.2

Date: 2018/10/15

插件只适配移动端,而且必须要用rem布局(设置html标签的font-size)

Update Logs

  • 新增data的prop,支持自定义三级联动数据,默认提供地址联动的数据AddressData.js
  • 新增inital的prop,支持默认选中初始值

avatar

Usage:

  1. 通过npm安装:yarn add cascading-picker or npm install cascading-picker --save
  2. 在SPA里模块引入或通过script标签引入, 然后直接使用组件
    // SPA模块引入. main.js
    import Vue from 'vue'
    import CascadingPicker from 'cascading-picker'
    import 'cascading-picker/dist/CascadingPicker.css'

    // 插件使用时提供一个name属性用于更改组件注册的名称,默认名称为CascadingPicker,主要是为了避免和其他ui库命名冲突
    Vue.use(CascadingPicker, {
        name: 'AlanCascadingPicker' // 此时组件注册后的名称为AlanCascadingPicker
    })
    // html引入script标签
    <link rel="stylesheet" href="node_modules/cascading-picker/dist/CascadingPicker.css"></link >
    <script src="node_modules/cascading-picker/dist/CascadingPicker.js"></script>
    // 必须先使用rem布局,App.vue
    export default {
        name: 'App',
        created() {
            // 手动实现的基于750像素设计图rem布局
            const doc = document.documentElement || document.body
            const docH = doc.getBoundingClientRect().width/7.5
            doc.style.fontSize = docH + 'px'
        }
    }

    // 在其他组件中直接使用CascadingPicker
    <template>
        <CascadingPicker 
            v-model="isPicker"
            :data="addressData"
            :initial="initial"
            closeOnClickModal
            @ok="selectAddress"
            @cancel="cancelAddress"
        />
    </template>

    <script>
        import addressData from 'cascading-picker/dist/AddressData'
        export default {
            name: 'example',
            data() {
                return {
                    isPicker: false,
                    addressData: addressData,
                    initial: {
                        first: '湖北',
                        second: '武汉市',
                        third: '洪山区'
                    }
                }
            },
            methods: {
                selectAddress(res) {
                    console.log(`你选中的是:${res.first},${res.second},${res.third}`)
                },
                cancelAddress() {   
                    console.log('你取消了地址选择器')
                }
            }
        }
    </script>

Component options

props

  • data [Array] 必选,三级联动的数据,可以选择插件提供的AddressData,或手动书写,但格式和key必须与AddressData一致
  • value [Boolean] 可选,控制地址选择器显示与否,可以使用v-model绑定变量,默认为false
  • initial [Object] 可选,格式为{first:'', second: '', third: ''},对应的value必须是data中的字符串,如果不是,则默认显示第一条
  • closeOnClickModal [Boolean] 可选,是否能够点击遮罩层来关闭,默认为false

emit events

  • ok,点击确定按钮触发。返回一个参数,格式为{first: '', second: '', third: ''},为选中的值
  • cancel,点击取消按钮触发(如果closeOnClickModal为true,点击遮罩层也会触发),如果开启closeOnClickModal也会触发,无参数返回值

slots

  • okText, 字符串,点击右侧确定按钮的文本
  • cancelText, 字符串,点击左侧取消按钮的文本

Somethind to say

  • 这个插件原本只是我很早之前写的,所以就没提供npm包,但是后来看到越来越多人给我发邮件,或提issue,或找我qq聊天询问一些问题,意识到还是有很多人对这个组件有需求。再三思考后,决定对组件进行功能优化和轻量重构,现在提供自定义数据,提供v-model绑定,提供默认选中值,这些改变都是为了更好的开发体验。
  • 很多人遇到的组件无法滚动问题,其实是移动端布局问题。必须声明这个组件是基于rem布局,为什么我一定要用rem布局?首先rem布局比普通百分比布局(或栅格响应式)体验更好。主流布局基本是纯rem或类似于手淘flexible.js的rem和viewport动态缩放一起使用。我很早之前在做移动端页面开发(app内嵌),在非常老的webview内使用rem布局是完全没有兼容问题的。所以我推荐大家使用rem布局(或直接使用flexible.js)
  • 另外推荐大家可以使用我的另外两个开源插件v-scollervue2-dialog,后者本身是对常用弹窗和滚动组件的集合。Thanks!