zoukankan      html  css  js  c++  java
  • vue3.0之响应式变量,生命周期

    <template>
      <div>
        <div class="ds-serch-box">
          <el-input v-model="search" placeholder="请输入姓名、警号、账号" style=" 250px"></el-input>
          <el-button type="primary" @click="getList">查询</el-button>
        </div>
        <el-table :data="tableData" stripe style=" 100%">
          <el-table-column prop="name" label="姓名"></el-table-column>
          <el-table-column prop="timeStr" label="日期"></el-table-column>
          <el-table-column label="ip" prop="ip" align="center"></el-table-column>
        </el-table>
    
        <div class="user-page">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage1"
            :page-size="rows"
            layout="total, prev, pager, next"
            :total="total"
          ></el-pagination>
        </div>
      </div>
    </template>
    
    <script>
    import addDialog from "./addDialog";
    import SourceMirror from "@/components/resource/dutyMirror";
    import {
      defineComponent,
      ref,
      reactive,
      onMounted,
      toRefs,
      getCurrentInstance
    } from "vue";
    export default {
      components: {
        addDialog
      },
      props: {},
      setup(props) {
        const { proxy } = getCurrentInstance();
        const data = reactive({
          search: "",
          currentPage1: 1,
          tableData: [],
          rows: 10,
          page: 1,
          total: 100
        });
        const getList = () => {
          const parmas = {
            page: data.page,
            rows: data.rows,
            search: data.search
          };
          SourceMirror.queryLogs(parmas).then(res => {
            if (res.data.code === 200) {
              data.total = res.data.data.total;
              data.tableData = res.data.data.list;
              proxy.$message({
                message: "成功",
                type: "warning"
              });
            } else {
              proxy.$message({
                message: "失败",
                type: "warning"
              });
            }
          });
        };
        const handleCurrentChange = page => {
          data.page = page;
          getList();
        };
        onMounted(() => {
          getList();
        });
        return {
          ...toRefs(data),
          getList,
          handleCurrentChange
        };
      }
    };
    </script>
    <style lang="less" scoped>
    .ds-serch-box {
      padding: 20px;
      display: flex;
      justify-content: flex-start;
    }
    .user-page {
      display: flex;
      justify-content: flex-end;
      margin-top: 20px;
    }
    </style>
    ref 用来创建简单的响应式变量
    reactive用来创建复杂的响应式对象,参考vue2.0里面的data,然后可以用toRefs去配合
  • 相关阅读:
    tomcat配置多实例
    内存溢出的三种情况及解决办法分析
    se最佳设置
    Squid 3.1.7通过mysql_auth方式认证
    java在linux下显示中文解决方法
    AD域批量的导入导出账号 转
    JSP技术分享:常用禁止缓存的四种方法
    大幅优化myeclipse的速度&关闭自动更新
    迷你图标集大集合:5000+ 30套免费的图标(不得不下,设计必备)
    【转】开发实战:舍得网44587行代码开发经验
  • 原文地址:https://www.cnblogs.com/lsc-boke/p/14627809.html
Copyright © 2011-2022 走看看