前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >useDynamicList vue 动态列表

useDynamicList vue 动态列表

作者头像
copy_left
发布2020-04-30 17:41:47
6100
发布2020-04-30 17:41:47
举报
文章被收录于专栏:方球方球

动态列表和普通列表的主要区别在于,动态列表内部维护一条自增列表。该列表映射了元素的添加顺序。提供基础列表函数及其他操作工具。 例如: marge等

Uesage

代码语言:javascript
复制
<style>

*{
  margin: 0;
  padding: 0;
}

li{
  list-style: none;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

ul{
  margin: auto;
  width: 400px;
}

li{
  display: flex;
  justify-content: space-between;
  padding: 8px 16px;
  border: 1px solid #eee;
  border-radius: 4px;
  background: #fff;
}

li + li{
  margin-top: 10px;
}

button{
  margin: 8px 12px;
  padding: 6px 12px;
  background: #efefef;
  border-radius: 4px;
  border: 0;
  box-shadow: 0;
}

button.full{
  display: block;
  box-sizing: border-box;
  width: 100%;
  
}

.card{
  margin: 20px auto;
  padding: 10px 20px;
  width: 400px;
  border-radius: 6px;
  box-shadow: 0 -4px 16px 4px rgba(100, 100, 100, .1);
}


.area{
  
  height: 200px;
  background: #eee;

}

.move{
  display: inline-block;
  margin: 10px;
  width: 50px;
  height: 50px;
  border-radius: 4px;
  border: 1px dashed orange;
}

</style>
<template>
  <div id="app">

      <div class="card">
        <ul>
          <li v-for='(item, index) of list ' :key='getKey(index)' >
            <p> value: {{ item }} </p>
            <p> key: {{ getKey(index) }} </p>
            <p> index: {{ index }} </p>
          </li>
        </ul>
      </div>

      <div class="card">

        <button @click='insert(0, 10)'> insert </button>
        <button @click='merge(1, [1, 2])'> merge </button>
        <button @click='replace(0, 100)'> replace </button>
        <button @click='remove(0)'> remove </button>
        <button @click='push(9)'> push </button>
        <button @click='pop'> pop </button>
        <button @click='unshift(90)'> unshift </button>
        <button @click='shift'> shift </button>
        <button @click='resetList(sortForm(list))'> sortForm </button>
        <button @click='() => resetList()'> clear </button>
        

      </div>
    
  </div>
</template>

<script>
import { ref } from 'vue'
import { useDynamic } from 'vx-hook'

export default {
  name: 'App',
  components:{
    
  },
  setup(){
    const [ list, utils ] = useDynamic([1, 2, 3, 4])
   
    return {

      list,
      ...utils
     
    }
  }
}
</script>

Params

  • initList 初始列表 any[]

Result

  • list 当前列表
  • utils 工具集
    • insert 插入 (index: number, data: any) => void
    • merge 合并 (index: number, arr: any[]) => void
    • replace 替换 ( index: number, data: any ) => void
    • remove 移除 (index: number) => void
    • getKey 获取自增标识 (index: number) => void
    • getIndex 获取自增下标 (data: number) => void
    • move 移动 (oldIndex: number, newIndex: number) => void
    • push 追加 (data: any) => void
    • pop 删除尾项 () => void
    • unshift 入栈 (data: any) => void
    • shift 出栈 () => void
    • sortForm 根据添加顺序排序 (arr: any[]) => void
    • resetList 重置 (arr: any[]) => void

vx-hook

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Uesage
  • Params
  • Result
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档