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

This is the main vue ponent. I want to make an ajax request and pass the data using the render method t

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1740218192a4210221.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信