Vue.js - access data from root instance within component

前端 未结 2 1023
野性不改
野性不改 2020-12-18 21:00

This seems like a fairly basic question but I can\'t seem to find a definitive (or even working) answer.

I have my root instance:

var vm = new Vue({
         


        
2条回答
  •  无人及你
    2020-12-18 21:20

    That's what "Props" are for:

    http://vuejs.org/guide/components.html#Props

    If you pass an object/array as a prop (what your events data will surely be), it's two-way syncing automatically - change events in the child, they are changed in the parent.

    If you pass simple values (strings, numbers - e.g. only event.name) via props, you have to explicitly use the .sync modifier: http://vuejs.org/guide/components.html#Prop_Binding_Types

提交回复
热议问题