这些方法主要是在这次做项目的过程中发现总结的来的,感觉也挺常用的,所以就简单的记录一下,希望下次不会再犯同样的错误。
子组件定义props,父组件传入数据,子组件在js中获取的时候使用,如果是在html里面,可以直接把变量渲染上去。子组件获取不到值时需要深拷贝
我就直接从代码上面来进行
js代码:
//子组件中,定义传入的变量的类型等
props: {
data: {
type: Array,
require: true
},
status: {
type: Boolean,
require: false
}
}
我们可以直接在生命周期函数里面打印props
mounted(){
let _this=this;
console.log(_this._props,9999);
}
方法一:
所以就可以直接拿取
mounted() {
let _this=this;
let {datas,status}=_this._props;
console.log(datas,999999);
},
方法二:<