最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue, how do I pass data to component in render method - Stack Overflow

programmeradmin14浏览0评论

This is the main vue ponent. I want to make an ajax request and pass the data using the render method to my app ponent, which is a standalone ponent in a different file. How do I pass this data and how can I retrieve it in my app ponent. I am learning Vue, I know how to do this with <template></template> but would like to know if it is possible to do it this way.

new Vue({
    el: '#app',
    data: {
        data: {}
    },
    mounted() {
        axios.get(":4000/autos").then(res => this.data = res.data)
    },
    render: h => h(App, this.data)
});

This is the main vue ponent. I want to make an ajax request and pass the data using the render method to my app ponent, which is a standalone ponent in a different file. How do I pass this data and how can I retrieve it in my app ponent. I am learning Vue, I know how to do this with <template></template> but would like to know if it is possible to do it this way.

new Vue({
    el: '#app',
    data: {
        data: {}
    },
    mounted() {
        axios.get("http://stag.cyberserge.:4000/autos").then(res => this.data = res.data)
    },
    render: h => h(App, this.data)
});
Share Improve this question asked Jun 8, 2017 at 4:50 Yasin YaqoobiYasin Yaqoobi 2,0503 gold badges31 silver badges39 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 16

Pass it as a property.

render(h){
  return h(App, {props: {appData: this.data}})
},

See the documentation here.

In your App ponent, add appData (or whatever you want to call it) as a property.

export default {
    props: ["appData"],
    ...
}

Here is an example of this working.

发布评论

评论列表(0)

  1. 暂无评论