父组件中调用子组件deviceBasicInfo:
<
deviceBasicInfo :
device='
deviceInfo'
></
deviceBasicInfo
>
export
default{
components:{
deviceBasicInfo:
resolve => {
require(['@/
components/
device/
deviceBasicInfo.
vue'],
resolve)}
},
data(){
deviceInfo:{}
},
mounted(){
var
_this=
this;
var
elem={};
elem[
"aaa"]=
_this.
$route.
params.
deviceId;
_this.
common.
doAction(
_this.
common.
aaa,
elem,
function(
result){
if(
result.
status==
1){
_this.
deviceInfo=
result;
}
});
},
子组件: 页面刷新时,子组件对象就为空了,只需要deviceInfo初始值设置参数值
<
template
>
<
div
style=
"float:left;"
>
<
div
class=
"proj-info-title1"
>项目名称:{{
deviceInfo.
projName}}
</
div
>
<
div
class=
"proj-info-title2"
>({{
deviceInfo.
projLocation}})
</
div
>
</
div
>
</
template
>
<
script
type=
"text/javascript"
>
export
default{
props: {
device:{
type:
Object
}
},
data(){
return{
deviceInfo:
{} //这里改成 this.device 就可以了
}
},
watch:{
device:{
handler:
function (
newValue,
oldValue) {
this.
deviceInfo=
newValue;
}
},
}
}
</
script
>