zoukankan      html  css  js  c++  java
  • vue的双向绑定示例

    摘自《vue.js实战》
     
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
      </head>
      <body>
        <div id="app">
          <p>总数为{{total}}</p>
          <my-component v-model="total"></my-component>
          <button @click="reduce">-1</button>
        </div>
        <script>
          Vue.component("my-component", {
    //子组件通过props:获取父组件的值
            props: ["value"],
            template: '<input :value="value" @input="handleCount">',
            methods: {
    //将子组件输入框的值通过$emit传给父组件
              handleCount: function (event) {
                this.$emit("input", event.target.value);
              },
            },
          });
          var v = new Vue({
            el: "#app",
            data: {
              total: 0,
            },
            methods: {
              reduce: function () {
                this.total--;
              },
            },
          });
        </script>
      </body>
    </html>
  • 相关阅读:
    论文复现的一些问题
    南京锐士方达猎头可拉黑
    Functional Ruby
    国内访问 Atom 源很慢 & 解决方案
    Linux 的硬链接与软链接
    Python小知识点(持续更新)
    MySQL小知识点(持续更新)
    Iterable Object, Iterator, Generator, Generator Iterator
    setTimeout函数在浏览器中和Node.js中的区别
    Several Python Tools/Utilities
  • 原文地址:https://www.cnblogs.com/kukai/p/12913161.html
Copyright © 2011-2022 走看看