为什么shouoji.json不显示,也就是点击手机不显示与手机相关的内容,还是显示笔记本,代码没有问题
<script>
export default {
name:"show",
data() {
var obj=this;
var url = "";
// url不能直接使用,要先定义,因为是局部变量
// get(url从public之后开始写)
if (obj.goodId == 1) {
url = "json/bjb.json";
}else if(obj.goodId == 2){
url = "json/shouji.json";
} else {
url = "json/bjb.json"
}
this.$http.get(url).then(function (res) {
obj.list=res.data;
})
return{
list:[]
}
},
props: {
// goodId来自于Right中的<GoodsList :goodId="1"></GoodsList>
goodId:Number
},
watch: {
goodId(){
var obj = this;
var url = "";
if (obj.goodId == 1) {
url = "json/bjb.json";
} else if (obj.goodId == 2){
url = "json/shouji.json";
}else{
url = "json/bjb.json";
}
this.$http.get(url).then(function (res) {
obj.list=res.data;
})
return{
list:[]
}
}
}
}
</script>