【问题标题】:Vue.js - How to pass data to component?Vue.js - 如何将数据传递给组件?
【发布时间】:2018-04-17 17:37:24
【问题描述】:

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
    }

});

日历.vue:

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

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

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

【问题讨论】:

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


    【解决方案1】:

    就这样?

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

    【讨论】:

    • 谢谢你的回答。但如果它是这样简单的方法,我不会问这样的问题:) this.someattr == undefined
    • 实际上我重新检查了所有内容,真可惜,一切正常。而且我不知道谁会否决这个答案,而不是我 :)
    • @Aleksandrs 谢谢 :)
    猜你喜欢
    • 2023-03-04
    • 2020-06-21
    • 2018-08-12
    • 2018-04-30
    • 2016-04-04
    • 1970-01-01
    • 2022-01-21
    • 2020-11-01
    • 2019-02-14
    相关资源
    最近更新 更多