• 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>
  • 相关阅读:
    考试剩余时间倒计时
    MVC URL处理
    .net core 使用DES加密字符串
    JS时间处理,获取天时分秒。以及浏览器出现的不兼容问题
    NLog使用说明
    开发工具集
    js模拟下载
    DataTable导出Excel
    Ajax提交打开新窗口,浏览器拦截处理;以及跨域问题
    jquery_DOM笔记
  • 原文地址:https://www.cnblogs.com/kukai/p/12913161.html
Copyright © 2020-2023  润新知