【问题标题】:I can not passing data by vue.js我无法通过 vue.js 传递数据
【发布时间】:2016-11-12 10:14:32
【问题描述】:

我是 vue.js 的新手.. 我使用 webpack + vue-cli 。

但我无法将数据从父母传递给孩子

这样的代码..

   <template lang="html">
  <div>
    <input v-model="parentMsg"></input>
    <br>
    <child v-bind:msg="parentMsg"></child>
  </div>
</template>

<script>
import child from './components/lists'
export default {
  data: function () {
    return {
      parentMsg: ''
    }
  },
  computed: {},
  ready: function () {},
  attached: function () {},
  methods: {},
  components: {
    child
  }
}
</script>

<template>
  <div>
    {{msg}}
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      msg: ''
    }
  }
}
</script>

顺便说一句... 如何将子组件绑定到父数组..

parent: data: array[...],
I want to bind the first of children's data to arr[0]
second to array[1]..

这可能吗?还是使用 v-for??

【问题讨论】:

  • 上面的代码不起作用..我改变了父母的输入..孩子没有改变

标签: vue.js


【解决方案1】:

在您的子组件中使用props 属性来接收父数据,例如:

<script>
export default {
  props: ['msg'],
  data: function () {
    return {

    }
  }
}
</script>

阅读更多关于这个here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多