Vue监听一个数组id是否与另一个数组id相同的方法
网络编程 2021-07-04 16:46www.168986.cn编程入门
今天长沙网络推广就为大家分享一篇Vue监听一个数组id是否与另一个数组id相同的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随长沙网络推广过来看看吧
数据list,结构为[{id:1,…},{id:2,…}],数据shoplist,结构为[{id:1,…},{id:2,…}],判断当shoplist.id等于list.id时显示list的数据。
.vue文件
<template> <div class="hello"> <div class="shoplist"> <button @click="clickButtonShopList">click me</button> <span>shoplist-id:</span><input type="text" v-model="shoplist[shopCount].id"> </div> <div class="list"> <button @click="clickButtonList">click me</button> <span>list-id:</span><input type="text" v-model="list[listCount].id"> </div> <input class="data" v-model="data"> <h2>{{list}}</h2> <h2>{{shoplist}}</h2> </div> </template>
.js文件
export default { data () { return { msg: 'Wele to Your Vue.js App', shopCount:0, listCount:0, data:'', list:[{id:1,name:'hello'},{id:2,name:'hello'},{id:3,name:'hello'},{id:4,name:'hello'},{id:5,name:'hello'}], shoplist:[{id:1,name:'hello'},{id:2,name:'hello'},{id:3,name:'hello'},{id:4,name:'hello'},{id:5,name:'hello'}] }; }, methods:{ clickButtonShopList:function () { this.shopCount++; this.shopCount=this.shopCount%this.shoplist.length; this.getData(); }, clickButtonList:function () { this.listCount++; this.listCount=this.listCount%this.list.length; this.getData(); }, getData:function () { this.data=''; if(this.shoplist[this.shopCount].id===this.list[this.listCount].id){ // this.data=this.list; this.data=this.list.map((element)=>{ return element.id+element.name; }).join(',') }else { this.data=''; } } }, mounted: function(){ this.getData(); } }
.less文件
.list{ margin-: 20px; } .data{ width: 500px; height:200px; border: 1px solid #666666; margin-: 20px; }
效果
刚开始时
两边id不
通过点击使得两边id相
以上这篇Vue监听一个数组id是否与另一个数组id相同的方法就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指