Vue.js - 如何将数据传递给组件?

时间:2017-11-05 13:16:00

标签: javascript laravel-5 vue.js vuejs2 vue-component

view.blade.php:

<div id="dashboard">
        <calendar someattr="xxx"></calendar>
        <calendar someattr="yyy"></calendar>
</div>

app.js:

import Calendar from './components/Calendar.vue';

new Vue({

    el: '#dashboard',

    components: {
        Calendar
    }

});

Calendar.vue:

    <template>
       ... some code ...
    </template>

<script>
    export default {
        props: ['someattr'],
        methods: {
          fetchEvents() {
             //HERE
          }
        }
    }
</script>

问题是:如何在方法fetchEvents中获取组件内的属性“someattr”?

1 个答案:

答案 0 :(得分:1)

就像那样?

<template>
  ... some code ...
</template>

<script>
  export default {
    props: ['someattr'],
    methods: {
      fetchEvents() {
        console.log(this.someattr)
      }
    }
  }
</script>