Vue子组件刷新父组件,实现切换后刷新子页面

1.父组件

在router-view 中增加isRouterAlive

<router-view
    v-if="isRouterAlive"
    ref="routerView"
/>

provide () {
   return {
     reload: this.reload
   }
},
data() {
   return {
     isRouterAlive:true,
  };
},
methods: {
 reload () {
    this.isRouterAlive = false
    this.$nextTick(function () {
    this.isRouterAlive = true
 })
}

 2.子组件引入父组件方法在调用的地方this.reload() 方法就行了

  name: 'subDemo',
  inject: ['reload'],

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
实现vue切换下拉框刷新组件组件中的信息,可以使用`props`和`watch`来实现组件之间的通信。 首先,在组件中定义一个`selected`的数据属性,并将其传递给组件作为`props`。例如: ```html <template> <div> <select v-model="selected"> <option v-for="option in options" :value="option.value">{{ option.label }}</option> </select> <child-component :selected="selected" /> </div> </template> <script> import ChildComponent from './ChildComponent.vue' export default { components: { ChildComponent }, data() { return { selected: '', options: [ { value: 'option1', label: '选项1' }, { value: 'option2', label: '选项2' } ] } } } </script> ``` 在这里,我们将`selected`作为`props`传递给了组件`ChildComponent`。 然后,在组件中,可以使用`watch`来监听`selected`的变化,并在变化时更新组件的数据。例如: ```html <template> <div> <p>当前选中的选项是:{{ selected }}</p> <p>其他组件的信息:{{ otherInfo }}</p> </div> </template> <script> export default { props: { selected: { type: String, required: true } }, data() { return { otherInfo: '' } }, watch: { selected: { immediate: true, handler(selected) { // 根据选中的选项更新组件的信息 this.otherInfo = `选项${selected}的信息` } } } } </script> ``` 在这里,我们使用了`watch`来监听`selected`的变化,并在变化时更新了组件的数据。同时,我们设置了`immediate`为`true`,以便在组件初始化时立即执行`handler`函数,从而初始化组件的数据。 通过这种方式,我们就可以实现vue切换下拉框时刷新组件组件中的信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄猿帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值