javascript - 传递 Props Vue js

标签 javascript vue.js vuejs2 vue-component

我试图将一个 prop 从主 Vue 实例传递到一个组件。我正在传递两个 Prop ,第一个有效,但第二个由于某种原因无效。

主实例

  var app7 = new Vue({
    el: '#app-7',
    template: `<div class="b">
                    <div>
                        <button class="c" v-on:click="previousDay">&lsaquo;</button>
                        <h1 >{{ this.ss }}</h1>
                        <button class="c" v-on:click="nextDay">&rsaquo;</button>
                    <div>
                    <emp-item
                    v-for="item in empList"
                    v-bind:emp="item"
                    v-bind:key="item.id">
                    v-bind:lines="lines"
                    </emps-item>
                    </div>`,
    data: function() {
    return {
    empList : l,
    lines: 0,
    day: 0
    }
// other stuff

组件

Vue.component('emp-item', {
    props: ['emp', 'lines'],
    template: `<div class="cv">
                <h6>{{emp.first_name}} {{ lines }}</h6>
                <canvas  v-on:mousedown="mouseDown" v-on:mousemove="mouseMove" v-on:mouseup="mouseUp" :id="'cv' + emp.id" class="canvas"  width="150" height="700"></canvas>

                </div>`,
    data: function() {
        return {

            rect : {},
            drag : false,
            startTime : 0,
            cv: ''

        }
    },
    watch: {
        lines: function () {
            console.log('watch: ');
        }
    },
// methods

如果 HTML 很重要

<div id="app-7">

    <app></app>

</div>

最佳答案

在绑定(bind)第二个 prop 之前关闭组件标签。它应该看起来像这样:

var app7 = new Vue({
    el: '#app-7',
    template: `<div class="b">
                    <div>
                        <button class="c" v-on:click="previousDay">&lsaquo;</button>
                        <h1 >{{ this.ss }}</h1>
                        <button class="c" v-on:click="nextDay">&rsaquo;</button>
                    <div>
                    <emp-item
                    v-for="item in empList"
                    v-bind:emp="item"
                    v-bind:key="item.id"
                    v-bind:lines="lines">
                    </emps-item>
                    </div>`,
    data: function() {
        return {
            empList : l,
            lines: 0,
            day: 0
    }
})

关于javascript - 传递 Props Vue js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47823395/

相关文章:

javascript - 计算属性未在 aurelia 中更新

vue.js - Vuejs防止数据为空

javascript - 一起使用 TypeScript 和 Vuejs 时的对象级变量?

javascript - 在过滤/搜索问题后更改输入 - VueJS

javascript - 多个甜蜜警报始终执行第一个确认回调

javascript - 使用 While 循环添加到字符串

vue.js - Vue.js 渲染函数是否允许返回 VNode 数组?

javascript - Vue.js 3 - 为什么在这种情况下导入 vue-router 不起作用?

javascript - 将字符串化的 JSON 数据渲染到表中

javascript - 你如何命名用于 Vue.js 组件中的 exjection 的 Axios 拦截器?