suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Javascript – Kommunikation zwischen Vue-Komponenten, Fehlerberichterstattung

Kommunikation zwischen Komponenten, Fehler „ReferenceError: Spitze ist nicht definiert“

    <body>
        <p id="app">
            <button v-on:click="tip = !tip">Toggle</button>
            <my-tip></my-tip>
        </p>
    </body>
    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript">
        var tipTemplate = {
          template: '<transition name="fade">\
                        <p v-if="tip" class="vertical-horizontal-center">\
                            <img src="../image/no-log.png">\
                            <h2>暂无记录</h2>\
                            <p class="aui-btn aui-btn-info">重新加载</p>\
                        </p>\
                    </transition>'
        }
        new Vue({
            el: "#app",
            data: {
                tip: false,
            },
            components: {
                'my-tip': tipTemplate,
                props: ['tip'],
            },
            created: function() {}
        })
    </script>
黄舟黄舟2776 Tage vor593

Antworte allen(4)Ich werde antworten

  • 我想大声告诉你

    我想大声告诉你2017-05-18 10:53:45

    var tipTemplate = {
              template: '<transition name="fade">\
                            <p v-if="tip" class="vertical-horizontal-center">\
                                <img src="../image/no-log.png">\
                                <h2>暂无记录</h2>\
                                <p class="aui-btn aui-btn-info">重新加载</p>\
                            </p>\
                        </transition>',
               props: ['tip']
            }
    <my-tip tip="tip"></my-tip>

    建议再看一下文档,组件的作用域那一块

    Antwort
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-18 10:53:45

    props: ['tip']应该写在var tipTemplate={}中,而不是写在 new Vue({})中,组件的作用域弄错了

    Antwort
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-18 10:53:45

    楼上的解答有问题,组件要动态属性绑定:

    <my-tip :tip="tip"></my-tip>

    整体如下:

        <body>
            <p id="app">
                <button v-on:click="tip = !tip">Toggle</button>
                <my-tip :tip="tip"></my-tip>
            </p>
        </body>
        <script type="text/javascript" src="../script/vue.js"></script>
        <script type="text/javascript">
            Vue.component('simple-counter', {
              template: '<transition name="fade">\
                            <p v-if="tip" class="vertical-horizontal-center">\
                                <img src="../image/no-log.png">\
                                <h2>暂无记录</h2>\
                                <p class="aui-btn aui-btn-info">重新加载</p>\
                            </p>\
                        </transition>',
              props: ['tip']
            })
            
            new Vue({
              el: '#app',
              data: {
                  tip: false
              },
              created: function() {}
            })
        </script>

    Antwort
    0
  • 天蓬老师

    天蓬老师2017-05-18 10:53:45

    在子组件上加一个v-if="tip"

    Antwort
    0
  • StornierenAntwort