<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>
看看Right.vue 里的手机那个GoodList的goodId是不是等于2,可能复制的时候没有更改