1、在blog-detail页面中:
/**
* 通过小程序的页面加载事件,获取其他页面跳转过来传递的作者名和文章id
*/
onLoad(options) {
this.author = options.author;
this.articleId = options.articleId;
// 获取传递的参数后,立即发请求获取详情信息
this.getArticleDetail();
},
<!-- 评论组件 -->
<view class="comment-box">
<article-comment-list :articleId="articleId" :author="author"/>
</view>
2、在article-comment-list组件中:
created() {
console.log(this.articleId+"1111");
console.log(this.author);
this.getArticelCommentList();
},
问题:在created生命周期函数中:无法获取blog-detail组件中通过props函数传递过来的参数,两者都是空值,同时接口函数报错,articleId||page为必传项。
而我尝试了一下在调用接口的方法放入mounted生命周期函数中:
mounted() {
console.log(this.articleId+"1111");
console.log(this.author);
this.getArticelCommentList();
},
此时就能够正常获取到传递过来的参数,并且正常请求接口,获取响应,请问一下老师,这是怎么一回事?