【问题标题】:Vue.js make use of global listVue.js 使用全局列表
【发布时间】:2016-03-02 08:36:40
【问题描述】:

我正在尝试在我的

中使用list

新的 Vue ,但它不工作。当我用一个组件尝试这个时,这是我的想法:

  Vue.component('employees', {
            template: '#employees',
            props:['list'],
            created() {
                this.list = JSON.parse(this.list);
            }
        });

        <employees list="{{ $employees }}"></employees>

那个 ^ 正在工作。 在我的组件中,我在列表中的 foreach 中显示所有员工。 但是我如何在new Vue 中使用列表,这样我就可以从每个组件中访问它。我知道你可以同步一个像这样的变量::selectedrole.sync="role" 但是这如何与列表一起工作?像这样的东西? :list="{{ $employees }}".sync="employees" ?

然后在我的new Vuethis?:

 new Vue({
            el: 'body',
            data:{
                list: '',
                created() {
                    this.list = JSON.parse(this.list);
                }
            }
        });

我正在使用 Laravel,$employees 只是一个员工对象。

我希望我已经解释清楚了。

谢谢

【问题讨论】:

    标签: javascript laravel vue.js


    【解决方案1】:

    您应该只将纯文本或变量绑定到组件道具。小胡子表达式在那里不起作用。

    即。

    <myComponent a="plain text" :b="obj"></myComponent>
    new Vue({
      data: {obj: {foo: 'bar'}}
      components: {myComponent: myComponent}
    })
    

    Props

    【讨论】:

      猜你喜欢
      • 2018-07-19
      • 2020-06-01
      • 2018-06-06
      • 2016-10-30
      • 1970-01-01
      • 2018-10-12
      • 2017-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多