zoukankan      html  css  js  c++  java
  • vue3-setup 的参数

    <template>
      <div id="app">
        <p>姓名:{{name}}</p>
        <p>
          <button @click="changeAge(-1)">-</button>
          年龄:{{age}}
          <button @click="changeAge(1)">+</button>
        </p>
        <p>
          出生年份:
          <button @click="changeYear(-1)">-</button>
          {{year}}
          <button @click="changeYear(1)">+</button>
        </p>
      </div>
    </template>
    
    <script>
    import { ref, computed, reactive,toRefs,watch } from "vue";
    export default {
      name: "app",
      data() {
        return {
          name: "xiaosan",
        };
      },
      setup(props,context) {
        // props 获取组建中定义的props
        // context
    
        props:{
          title:String
        }
        const data = reactive({ // 建立一个响应式对象
          name: "小四",
          age: 18,
          year: computed({
            get: () => {
              return 2020 - data.age;
            },
            set: (val) => {
              data.age = 2020 - val;
            },
          }),
        });
        function changeAge(val) {
          data.age += val; //想改变值或获取值 必须.value
          console.log(props.title)
        }
        watch(()=>props.title,(newTitle,oldTitle)=>{
          console.log(newTitle,oldTitle)
          context.emit('title-changed')
        }),
        function changeYear(val) {
          data.year = data.year + val;
        }
        return {
          //必须返回 模板中才能使用
          ...toRefs(data),//讲响应式的对象变为普通对象 在家。。。结构,在模板中就可以直接使用属性,不用data.name
          changeAge,
          changeYear,
        };
      },
    };
    </script>
  • 相关阅读:
    Scrum是脆弱的,不敏捷的
    Solr 全文搜索
    Java并发之线程封闭
    Java中的关键字synchronized
    Java并发框架:Executor
    锁,表锁,行锁,页锁,共享锁,排他锁
    事务及事务隔离
    MySql存储引擎:innodb myisan memory
    树,二叉树
    B树(B-树) 、B+树
  • 原文地址:https://www.cnblogs.com/lxz-blogs/p/13595148.html
Copyright © 2011-2022 走看看