简体   繁体   English

在Vue组件中使用控制器数据

[英]Use controller data in Vue component

I'm building an app with Laravel (Spark) and Vue. 我正在使用Laravel(Spark)和Vue构建应用程序。

The user can create an entry: form on the left, preview on the right, using v-model to bind the preview to the inputs. 用户可以创建一个条目:使用v-model将预览绑定到输入,在左边的窗体在右边的预览中。 That works 这样可行

Now, when the user edits an existing entry, I get the entry in question and pass it on to the view like so: 现在,当用户编辑现有条目时,我得到了该条目并将其传递给视图,如下所示:

return view('app/form/edit', array('form' => $form));

And here's my component: 这是我的组件:

Vue.component('create-form', {
        props: ['user'],

    data: function() {
        return {
            title: "",
            description: ""
        };
    },

});

Now, my question: how do I access the $form variable in my Vue component? 现在,我的问题是:如何在Vue组件中访问$form变量?

Most question I see related to this are either iterating over a loop or pull in data with Ajax (I already have the data on the page so I don't think that's the way to go here). 我看到的与此相关的大多数问题要么是循环遍历,要么是使用Ajax提取数据(我已经在页面上保存了数据,所以我认为这不是要解决的方法)。

Any advice on how to proceed would be greatly appreciated :) Thanks Jan 任何有关如何进行的建议将不胜感激:)谢谢扬

here what I do on such cases: 在这种情况下,我该怎么做:

If it is a model: 如果是模型:

<my-component :prop="{{ $some_model->toJson() }}"></my-component>

If it is a simple array: 如果是简单数组:

<my-component :prop="{{ json_encode($some_array) }}"></my-component>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM