本文实例为大家分享了vue实现多标签选择器展示的具体代码,供大家参考,具体内容如下

实现效果

实现代码

document

.not-active {

display: inline-block;

font-size: 12px;

margin: 5px 8px;

}

span {

margin: 0 2px;

}

{{category.name}}:

不限

不限

{{ child.name }}

{{ child.name }}

清空已选:

v-for='(condition, index) in conditions'

:key="condition.id"

type="primary"

:closable="true"

size="small"

:disable-transitions="true"

@close='removecondition(condition, index)'

@click='removecondition(condition, index)'>

{{condition.name}}

// 简单封装一个公用组件

vue.component('my-tag', {

template: "",

methods: {

clickchild() {

this.$emit("click-child")

}

}

});

var app = new vue({

el: '#app',

data() {

return {

categories, // 分类标签,可从外部加载配置

conditions: [] // 已选条件

}

},

watch: {

// 监听条件变化,按照请求接口拼装请求参数

conditions(val){

let selectedcondition = {};

for(let categorie of this.categories){

let selected_list = [];

for(let child of categorie.children){

if(child.active){

selected_list.push(child.name);

}

}

selectedcondition[categorie.name] = selected_list.join("|")

}

console.log(selectedcondition);

}

},

methods: {

// 处理标签点击事件,未选中则选中,已选中则取消选中

clickchild(category, categoryindex, child, childindex) {

let uid = `${categoryindex}-${childindex}`

child.uid = uid;

console.log(uid)

// 取消选择

if (child.active === true) {

category.count--;

child.active = false;

this.conditions.foreach((conditionchild, index) => {

if (conditionchild.uid === child.uid) {

this.conditions.splice(index, 1);

}

});

// 选择

} else {

category.count++;

child.active = true;

this.conditions.push(child);

}

},

// 清除已选整个类别标签

clearcategory(category, categoryindex) {

category.count = 0;

// 可选列表均为未选中状态

category.children.foreach(child => {

child.active = false;

})

// 清空该类已选元素

for (let index = this.conditions.length - 1; index >= 0; index--) {

const conditionchild = this.conditions[index];

if (conditionchild.uid.startswith(categoryindex)) {

this.conditions.splice(index, 1);

}

}

},

// 移除一个条件

removecondition(condition, index) {

let categoryindex = condition.uid.split("-")[0];

this.categories[categoryindex].count --;

this.conditions.splice(index, 1)

condition.active = false;

},

// 清空所有条件

clearcondition() {

for(let i = this.conditions.length-1; i >=0 ; i--){

this.removecondition(this.conditions[i], i);

}

}

}

});

标签筛选的数据格式

data.js

var categories = [{

name: '品牌',

count: 0,

children: [{

name: '联想',

}, {

name: '小米',

}, {

name: '苹果',

}, {

name: '东芝',

}]

}, {

name: 'cpu',

count: 0,

children: [{

name: 'intel i7 8700k',

}, {

name: 'intel i7 7700k',

}, {

name: 'intel i9 9270k',

}, {

name: 'intel i7 8700',

}, {

name: 'amd 1600x',

}]

}, {

name: '内存',

count: 0,

children: [{

name: '七彩虹8g',

}, {

name: '七彩虹16g',

}, {

name: '金士顿8g',

}, {

name: '金士顿16g',

}]

}, {

name: '显卡',

count: 0,

children: [{

name: 'nvidia 1060 8g',

}, {

name: 'nvidia 1080ti 16g',

}, {

name: 'nvidia 1080 8g',

}, {

name: 'nvidia 1060ti 16g',

}]

}]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。

vue多html标签,Vue实现多标签选择器相关推荐

  1. vue项目部署到服务器后浏览器标签上的小图标消失不见

    背景: 最近在开发项目过程中发现一个问题,项目部署到服务器后在浏览器打开,会发现浏览器标签上的小图标消失不见了.百度查找问题,网上给出了许多解决的方案,例如清除浏览器缓存.把图标的相对路径改成绝对路径 ...

  2. vue 项目中,动态修改浏览器标签页的图标

    vue 项目中,动态修改浏览器标签页的图标 需求: 项目中有一个入口可以修改平台的名称和图标,图标同步展示为浏览器页签的图标 实现: 1.找到项目中的app.vue 文件,动态创建link标签,调用后 ...

  3. vue template html属性,详解template标签用法(含vue中的用法总结)

    一.html5中的template标签 html中的template标签中的内容在页面中不会显示.但是在后台查看页面DOM结构存在template标签.这是因为template标签天生不可见,它设置了 ...

  4. vue提示音_vue中使用audio标签进行消息提示

    本文实现的功能是:有新的消息更新时,页面会播放提示音,提示的声音会播放15秒,然后停止播放,如果在停止播放之前又有新的消息进来,则会重新计时15秒. 首先,添加audio标签,引入资源文件. 在aud ...

  5. 怎么将vue模板转换为html,vue中自定义html文件的模板

    如果默认生成的 HTML 文件不适合需求,可以创建/使用自定义模板. 一是通过 inject 选项,然后传递给定制的 HTML 文件.html-webpack-plugin 将会自动注入所有需要的 C ...

  6. vue教程2 【Vue组件化编程】 组件的创建和使用 非单文件组件和单文件组件的区别

    组件 实现局部功能的代码和资源的集合 非单文件组件 1.定义组件(创建组件) 2.注册组件 3.使用组件(写组件标签) 定义 使用Vue.extend(options)创建,其中options和new ...

  7. Vue教程1 【Vue核心】

    Vue.js 中文文档 (bootcss.com) 使用vue插件 GitHub - vuejs/devtools: ⚙️ Browser devtools extension for debuggi ...

  8. Vue HTML:在Vue上写Html遇到的一些问题,html的首行缩进,html的行间距,element UI的回到顶部不显示

    Vue & HTML:在Vue上写Html遇到的一些问题,html的首行缩进,html的行间距,element UI的回到顶部不显示 资源: HTML 教程- (HTML5 标准) 怎么快速上 ...

  9. vue 1.0和vue 2.0的变化和区别

    一.在每个组件模板,不在支持片段代码 vue 1.0是 <template><h3>我是组件</h3><strong>我是加粗标签</strong ...

  10. vue教程2:vue基础

    el挂载点 el用来设置vue实例作用范围的元素 通常使用id选择器,例如el: "#app".另外,还支持class.css等其他选择器,不过一般建议使用id选择器 不能挂载到h ...

最新文章

  1. Angular 选项卡
  2. 苹果官方Instruments工具之Automation的介绍
  3. Ubuntu安装apache+Yii2
  4. html ctf查找,Web CTF 解题思路总结—南京邮电大学攻防平台writeup
  5. 关于海量分页的补充说明(转)
  6. Vue首屏性能优化组件
  7. [bzoj3140] [Hnoi2013]消毒
  8. python3.6和2.7的区别_Python2.7与3.6的一些区别
  9. CodeBlocks常用快捷键
  10. 拓端tecdat|R语言Copula估计边缘分布模拟收益率计算投资组合风险价值VaR与期望损失ES
  11. 基于变分模态分解与麻雀优化最小二乘支持向量机的短期电力负荷预测(VMD-SSA-LSSVM)
  12. TM2008 Preview体验
  13. 错误码 0x8007007b 解决
  14. iOS定位经纬度转换
  15. 神奇代码岛BOX获500万美元天使轮融资 构建编程少年元宇宙
  16. 宝二爷,一个以太坊铁杆粉为何转投EOS?
  17. 2022年你应该知道的十大Python库
  18. 如何统计钣金文档中向上和向下折弯的个数
  19. 前端js通过图片路径,展示图片
  20. 台式计算机如何拆硬盘,机械硬盘怎么拆开?台式机3.5英寸机械硬盘拆卸方法图文教程...

热门文章

  1. 大数据应用的优势在哪
  2. 如何选择一个合适的大数据可视化工具
  3. 寻找链表中值域最小的节点并移到链表的最前面
  4. jsp获取连接池的实时连接数_数据库连接池原理分析及模拟实现
  5. android 跑windows软件,Windows 10 Mobile用户现可让设备跑上Android软件
  6. Maven本地环境配置(Win10)
  7. [JLOI2014]松鼠的新家【树上差分】
  8. Loadrunner脚本函数
  9. Nova 操作汇总(限 libvirt 虚机) [Nova Operations Summary]
  10. git 远程代码被覆盖