方法一:通过在父组件的onShow
调用子组件的方法(请求)
实现页面的刷新
父组件 html
<stock :obj="obj" ref="stock" />
js
onShow() {
console.log('我是onshow')
this.$refs.stock.getData()
},
子组件
js 请求的参数必须在data中初始化
data() {
return {
tableData:{
},
info:{
directorEnabled: JSON.parse(uni.getStorageSync('userInfo')).directorEnabled,
managerId:JSON.parse(uni.getStorageSync('userInfo')).branch.managerId,
token: uni.getStorageSync('token'),
beginTime: 1600854391,
endTime:1700854463,
displayEnable: false,
businesserId:JSON.parse(uni.getStorageSync('userInfo')).directorEnabled?JSON.parse(uni.getStorageSync('userInfo')).id:''
},
};
},
方法:
async getData(type){
let json = await api.tarvelIndex(this.info)
console.log(json,'我是json')
if(json.status === 200){
json.data.map(item=>{
if(item.id = this.obj.id){
this.tableData = item
}
})
}
},
方法二:v通过-if 在父组件中的onShow 创建和 onHide销毁组件
父组件 html
<stock :obj="obj" v-if="flag" />
js
onShow() {
this.flag = true
},
onHide() {
this.flag = false
},
子组件正常使用