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

url-mapper-vue

v1.4.0

Published

Map the url search params to the data of the vue component.

Downloads

11

Readme

中文

url-mapper-vue

Provides vue directives and methods that allow URL parameters to be bound bidirectionally with the data properties of a Vue component, compatible with Vue2 and Vue3.

Installation

npm install url-mapper-vue --save

Usage

First step, register the directive

import { UrlMapperDirective } from 'url-mapper-vue'
Vue.use(UrlMapperDirective)

Directive v-url-map (vue directives)

Use on component nodes with v-model, such as in form components.

Component definition: v-url-map={url, type, value, callback}

  • url (required): URL parameter variable name
  • type (required): The value type of the component data property, supporting the following types:
    • boolean
    • string
    • number
    • array|number: array of numbers
    • array|string: array of strings
    • arrays|array|number: two-dimensional array of numbers
    • arrays|array|string: two-dimensional array of strings
  • value (required): The data property of the Vue component, for example, if it is data.form.age, then it is form.age (vue2). (Vue3 does not support expression access, it needs to be written as 'form.age').
  • callback (optional): The method callback of component methods, which will be called after initialization is completed (the value of the URL parameter in the page will be mapped to the component data during initialization).

example (vue2):

    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="活动名称">
        <el-input
          v-url-map="{url:'name',type:'string', value:form.name}"
          v-model="form.name">
        </el-input>
      </el-form-item>

      <el-form-item label="活动区域">
        <el-select v-model="form.region"
        placeholder="请选择活动区域"
        v-url-map="{url:'region',type:'string', value:form.region}"
        >
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="活动时间">
        <el-date-picker
          v-url-map="{url:'date1',type:'array|string', value:form.date1}"
          v-model="form.date1"
          value-format="yyyy-MM-dd HH-mm-ss"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
    </el-form>

vue 插件

安装:

import { UrlMapperPlugin } from 'url-mapper-vue'

Vue.use(UrlMapperPlugin)

methods:

  • $setDataFromUrl

    • url params to component data。 参数(arguments): { [key]: { path: [data path], type: [type] } }
      • key: url 参数名称
      • data path: data 属性的路径,例如data.form.age, 则是 'form.age'.
      • type: 组件data属性的值类型
  • $setUrlParams

  • component data to url params。 参数 (arguments): js 对象.

  • $clearUrlParams

    • clear url params.

Example:

$setDataFromUrl

In vue component:

...
const config = {
  name: { path: 'form.name', type: 'string' },
  region: { path: 'form.region', type: 'string' },
  date1: { path: 'form.date1', type: 'array|string' },
  type: { path: 'form.type', type: 'array|number' },
  desc: { path: 'form.desc', type: 'string' }
}
this.$setDataFromUrl(config) // map url params to component data.
...

$setUrlParams

In vue component:


onSubmit () {
	// do sth...
  const params = {
    name: 'xxx',
    region: 'japan',
    type: [1,2,3],
    ...
  }
	this.$setUrlParams(params) // map data to url params.
},

$clearUrlParams

In vue component:

reset() {
	// ...
	this.$clearUrlParams() // clear url params
}