南强小屋 Design By 杰米
数据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: 'Welcome 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-top: 20px;
}
.data{
width: 500px;
height:200px;
border: 1px solid #666666;
margin-top: 20px;
}
效果:
刚开始时:
两边id不同时:
通过点击使得两边id相同时:
以上这篇Vue监听一个数组id是否与另一个数组id相同的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
Vue,监听,数组id
南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米
暂无Vue监听一个数组id是否与另一个数组id相同的方法的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。


