How to pass data(json) to vue instance

前端 未结 4 1801
囚心锁ツ
囚心锁ツ 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:14

    Your solution was nearly there but you don't need a prop, rather use a data attribute and assign the JSON via a method:

    new Vue({
        el: '#app',
        data: {
            json: {},
        },
        methods: {
        	setJson (payload) {
            	this.json = payload
            },
        }
    })
    
    
    {{ json }}

    You would just assign your Laravel data to the setJson methods payload, i.e.

    :json="setJson({{ $prices }})
    

提交回复
热议问题