Vue笔记(props和 mounted)

1.mounted

  1.1mounted中使用$nextTick会导致页面挂掉

1 mounted() {
2 // 页面卡死
3     this.$nextTick(() => {
4       this.setUrl()
5     })
6   }

2.props

  2.1props传过去的值,第一时间在mounted是获取不到的。因为是异步传值的。

  解决方法:(1)使用watch;(2)将需要进行的处理在父组件进行操作,然后将操作完的值直接传给子组件。

 1 watch: {
 2   datas: function (val) {
 3      
 4    }
 5  }
 6  7 (父)
 8 <examAchSearchHeader :exprotUrl="exprotUrl"></examAchSearchHeader>
 9 ...
10 this.exportUrl = XXXX
11 (子)
12 props: {
13     exportUrl: String
14 }

  2.2通过props传给子组件的值变化后子组件接收到 和 通过refs访问子组件方法中使用接收到的参数变化的顺序问题

  通过refs访问时,接收到的参数是变化前的参数。还是因为异步的问题。可以强制赋值改变,或用watch等。

 1 // parent
 2 <examAchTable ref="achTable" :dataList="examAchList"></examAchTable>
 3 
 4 // 若这里不强制赋值一下,在examAchList变化后直接调用子组件的transData方法时,子组件dataList仍是变化前的值
 5 this.$refs.achTable.dataList = this.examAchList
 6 this.$refs.achTable.transData(res.data.totalRecord)
 7 
 8 // child
 9 transData(total) {
10       if (this.dataList) 
11     // ...
12 }

持续更新中...

转载于:https://www.cnblogs.com/ljwsyt/p/10594923.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值