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

address-element-vue

v1.0.11

Published

基于elementUi的vue 省市区三级联动组件 ,返回省市id与名称,可以清除所有,可以搜索

Downloads

23

Readme

address-element-vue

基于elementUi的vue 省市区三级联动组件 ,返回省市id与名称

Build Setup

npm i address-element-vue

使用

全局使用
main.js
import Address from 'address-element-vue'
Vue.use(Address)
局部使用 
import {Address} from 'address-element-vue'
components: {
           addressSelect: Address
      },
示例:
   <template>
     <div id="app">
       <address-select :order-address="orderAddress"></address-select>
       <button @click="sure">确定</button>
     </div>
   </template>
   
   <script>
   import {Address} from 'address-element-vue'
   export default {
     name: 'App',
       data(){
         return {
             orderAddress:{city_id: 110001,
                 city_name: "北京市",
                 province_id: 110000,
                 province_name: "北京市",
                 region_id: 110101,
                 region_name: "东城区"}
         }
     },
     components: {
          addressSelect: Address
     },
       ,methods:{
         sure(){
             console.log(this.orderAddress)
           }
       }
   }
   </script>
  • orderAddress 可以自定义 是一个对象:
{province_id:'',province_name:'',city_id:'',city_name:'',region_id:'',region_name:''}

获取与更改数据库

  • sql文件位于mysql/bd_area.sql
  • 组件引用的省市区地址文件位于 src/assets/address.json
  • 以下为php代码导入数据库,以及生成address.json文件的示例
//将address.json文件导入数据库
 public static function initData(){
       $data=file_get_contents("./address.json");
       $datas=json_decode($data,true);
       $temp=[];
       foreach ($datas as $vo){
           $temp[]=['id'=>$vo['code'],'name'=>$vo['name'],'pid'=>0,'level'=>1];
           if($vo['cityList']){
               foreach ($vo['cityList'] as $v){
                   if($v['code']==$vo['code']){
                       $code=$v['code']+1;
                   }else{
                       $code=$v['code'];
                   }
                   $temp[]=['id'=>$code,'name'=>$v['name'],'pid'=>$vo['code'],'level'=>2];
                   if($v['areaList']){
                       foreach ($v['areaList'] as $val){
                           $temp[]=['id'=>$val['code'],'name'=>$val['name'],'pid'=>$code,'level'=>3];
                       }
                   }
               }
           }
       }
       self::insertAll($temp);
   }
//生成address.json
   public static function getVueJson(){
      $res= self::select();
      $temp=[];
      $temp1=[];
      $temp2=[];
      foreach ($res as $vo){
          $temp1[$vo['id']]=$vo;
          if($vo['pid']==0){
              $temp[$vo['id']]=['value'=>$vo['id'],'label'=>$vo['name'],'id'=>$vo['id']];
          }else{
              if($vo['level']==2){
                  $temp[$vo['pid']]['children'][]=['value'=>$vo['id'],'label'=>$vo['name'],'id'=>$vo['id']];
              }
              if ($vo['level']==3){
                  $temp2[$vo['pid']][]=['value'=>$vo['id'],'label'=>$vo['name'],'id'=>$vo['id']];
              }
          }
      }
    foreach ($temp as &$vo){
          if(isset($vo['children'])){
              foreach ($vo['children'] as &$v){
                  if(isset($temp2[$v['id']])){
                      $v['children']=$temp2[$v['id']];
                      unset($temp2[$v['id']]);
                  }
              }
          }
    }
   return file_put_contents('addressListsForVue.json',json_encode(['data'=>array_values($temp),'list'=>$temp1]));
   }

发布说明

1.0.11

  • 添加局部引用功能

1.0.9

无效

1.08

1.0.7

  • 修改1.0.5为解决的问题
  • 修改因为未正确引入地址而导致无法初始化数据的问题

1.0.6

  • 修复因webpack引起的路由加载问题

1.0.5

  • 修改因为未正确引入地址而导致无法初始化数据的问题

# 源码地址 GitHub地址