1. 数组过滤问题
<script>
new Vue({
el:"#app",
data:{
carts:[
{
checked:true
}
]
},
methods:{
getCarts(){
this.carts=this.carts.filter(c=>c.checked)
}
}
})
</script>
2.把一个数组中的一个对象(a) 赋值给一个对象(b),当改变 b时a也随着改变,解决此问题:
<script>
new Vue({
el:"#app",
data:{
cart:{},
carts:[]
},
methods:{
getCart(index){
let str =JSON.stringify( this.carts[index])
this.cart=JSON.parse(str)
}
}
})
</script>
3. 获取路径参数
http://www.ypg.com/list.html?cat_id=231
location.search.match(/cat_id=(\d+)/)[1]
<script>
new Vue({
el:"#app",
data:{
catid:location.search.match(/cat_id=(\d+)/)[1]
}
})
</script>