How to pass data(json) to vue instance

前端 未结 4 1796
囚心锁ツ
囚心锁ツ 2020-12-31 23:53

I have a simple Vue instance and want to pass json from the backend to vue without HTTP request because it\'s always the same.

I\'ve tried do this with props, but it

4条回答
  •  一个人的身影
    2021-01-01 00:31

    I have upvoted this answer first, but I have to change my vote (can't do it actually not enough reputation...).

    Please do not set the data this way, because it will trigger an error like this: [Vue warn]: You may have an infinite update loop in a component render function

    If anything will use the data you set this way (watch, render components based on it) you will have an infinite loop.

    When you use this method:

    1. you set the data in the render function (in the template)
    2. if something triggers a re-render, the data will be set again
    3. anything using this data will have to re-render, which may cause a re-render on the main vue instance

    This will cause the infinite loop.

    LinusBorg have an explanation here.

提交回复
热议问题