慕课小慕读书后台总结

67 篇文章 2 订阅
22 篇文章 0 订阅
  1. 登录输入框,如果没有数据自动聚焦
mounted() {
    if (this.loginForm.username === "") {
      this.$refs.username.focus();
    } else if (this.loginForm.password === "") {
      this.$refs.password.focus();
    }
  },
  1. 密码框的显示影藏切换
 :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
  @click="showPwd"
   showPwd() {
      if (this.passwordType === "password") {
        this.passwordType = "";
      } else {
        this.passwordType = "password";
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
  1. 通过浅拷贝实现属性过滤
const _query = Object.assign({}, query)
 delete _query.redirect
  1. 对token的分类处理
const whiteUrl = ['/login']
	
service.interceptors.request.use(
 config => {
   const url = config.url.replace(config.baseURL, '')
   if (whiteUrl.some(wl => url === wl)) {
     return config
   }
   config.headers['Authorization'] = `Bearer ${getToken()}`
   return config
 },
  1. token - cokie的封装
import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'

export function getToken() {
 return Cookies.get(TokenKey)
}

export function setToken(token) {
 return Cookies.set(TokenKey, token)
}

export function removeToken() {
 return Cookies.remove(TokenKey)
}

使用

import { getToken, setToken, removeToken } from '@/utils/auth'
setToken(data.token)

  1. 对路由的监听
  watch: {
    $route: {
      handler: function (route) {
        const query = route.query;
        console.log("query", query);
        if (query) {
          this.redirect = query.redirect;
          this.otherQuery = this.getOtherQuery(query);
        }
      },
      immediate: true,
    },
  },
  1. 表格排序 + 搜索通用 + 搜索高亮
@sort-change="sortChange"

    sortChange(data) {
      console.log("data", data);
      const { prop, order } = data;
      if (prop === "id") {
        this.sortByID(order);
      }
    },
    sortByID(order) {
      console.log("this.listQuery", this.listQuery);
      if (order === "ascending") {
        this.listQuery.sort = "+id";
      } else {
        this.listQuery.sort = "-id";
      }
      this.handleFilter();
    },
handleFilter() {
      console.log("listQuery", this.listQuery);
      this.listQuery.page = 1;
      this.refresh();
    },

 refresh() {
      this.$router.push({
        path: "/book/list",
        query: this.listQuery,
      });
    },
    
      beforeRouteUpdate(to, from, next) {
    console.log("to", to.path);
    console.log("from", from.path);
    console.log("next", next.path);
    if (to.path === from.path) {
      const newQuery = Object.assign({}, to.query);
      const oldQuery = Object.assign({}, from.query);
      console.log("newQuery", newQuery);
      console.log("oldQuery", oldQuery);
      console.log("oldQuery", JSON.stringify(oldQuery));
      console.log("newQuery", JSON.stringify(newQuery));
      if (JSON.stringify(newQuery) !== JSON.stringify(oldQuery)) {
        console.log("等不等");
        this.getList();
      }
    }
    next();
  },
  getList() {
      this.listLoading = true;
      listBook(this.listQuery).then((response) => {
        const { data, total } = response;
        this.list = data;
        this.total = total;
        this.listLoading = false;
        console.log("lisk", this.list);
        this.list.forEach((book) => {
          book.titleWrapper = this.wrapperKeyword("title", book.title);
          book.authorWrapper = this.wrapperKeyword("author", book.author);
        });
      });
    },
    wrapperKeyword(k, v) {
      function highlight(value) {
        return '<span style="color: #1890ff">' + value + "</span>";
      }
      if (!this.listQuery[k]) {
        return v;
      } else {
        return v.replace(new RegExp(this.listQuery[k], "ig"), (v) =>
          highlight(v)
        );
      }
    },
  1. 过滤器
 filters: {
    valueFilter(value) {
      return value ? value : "无";
    },
    }
  1. 表格里的数据结构 和图片打开
 <template slot-scope="{ row: { cover } }">
          <a :href="cover" target="_blank">
            <img :src="cover" style="width: 120px; height: 180px" />
          </a>
        </template>
  1. 分页器二次封装
<template>
  <div :class="{'hidden':hidden}" class="pagination-container">
    <el-pagination
      :background="background"
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { scrollTo } from '@/utils/scroll-to'

export default {
  name: 'Pagination',
  props: {
    total: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50]
      }
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.$emit('pagination', { page: this.currentPage, limit: val })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    },
    handleCurrentChange(val) {
      this.$emit('pagination', { page: val, limit: this.pageSize })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    }
  }
}
</script>

<style scoped>
.pagination-container {
  background: #fff;
  padding: 32px 16px;
}
.pagination-container.hidden {
  display: none;
}
</style>

使用
 <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.pageSize"
      @pagination="refresh"
    />

  1. 新手引导
https://www.jianshu.com/p/8cdef1041086
  1. 表格固定最后一列
 fixed="right"
  1. 吸顶组件
<template>
  <div :style="{height:height+'px',zIndex:zIndex}">
    <div
      :class="className"
      :style="{top:(isSticky ? stickyTop +'px' : ''),zIndex:zIndex,position:position,width:width,height:height+'px'}"
    >
      <slot>
        <div>sticky</div>
      </slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Sticky',
  props: {
    stickyTop: {
      type: Number,
      default: 0
    },
    zIndex: {
      type: Number,
      default: 1
    },
    className: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      active: false,
      position: '',
      width: undefined,
      height: undefined,
      isSticky: false
    }
  },
  mounted() {
    this.height = this.$el.getBoundingClientRect().height
    window.addEventListener('scroll', this.handleScroll)
    window.addEventListener('resize', this.handleResize)
  },
  activated() {
    this.handleScroll()
  },
  destroyed() {
    window.removeEventListener('scroll', this.handleScroll)
    window.removeEventListener('resize', this.handleResize)
  },
  methods: {
    sticky() {
      if (this.active) {
        return
      }
      this.position = 'fixed'
      this.active = true
      this.width = this.width + 'px'
      this.isSticky = true
    },
    handleReset() {
      if (!this.active) {
        return
      }
      this.reset()
    },
    reset() {
      this.position = ''
      this.width = 'auto'
      this.active = false
      this.isSticky = false
    },
    handleScroll() {
      const width = this.$el.getBoundingClientRect().width
      this.width = width || 'auto'
      const offsetTop = this.$el.getBoundingClientRect().top
      if (offsetTop < this.stickyTop) {
        this.sticky()
        return
      }
      this.handleReset()
    },
    handleResize() {
      if (this.isSticky) {
        this.width = this.$el.getBoundingClientRect().width + 'px'
      }
    }
  }
}
</script>

 <sticky :z-index="10" :class-name="'sub-navbar ' + postForm.status">
        <el-button v-if="!isEdit" @click.prevent.stop="showGuide"
          >显示帮助</el-button
        >
        <el-button
          v-loading="loading"
          style="margin-left: 10px"
          type="success"
          class="submit-btn"
          @click="submitForm"
        >
          {{ isEdit ? "编辑电子书" : "新增电子书" }}
        </el-button>
      </sticky>
  1. 上传组件的封装
  2. 多数据表单的设置
    假设表单有很多数据,需要在请求回数据,填写。那我们都要把这些数据,设置成响应式吗?
    写一个方法
 this.setData(data);

在方法里赋值

 setData(data) {
      const {
        title
      } = data;
      this.postForm = {
        title
      };
      数据清空
       toDefault() {
      this.postForm = Object.assign({}, defaultForm);
      this.fileList = [];
      this.contentsTree = [];
    },
  1. 表单数据校验,多级数据做数据的映射
  const validateRequire = (rule, value, callback) => {
      console.log("rule", rule);
      if (value === "") {
        this.$message({
          message: rule.field + "为必传项",
          type: "error",
        });
        callback(new Error(rule.field + "为必传项"));
      } else {
        callback();
      }
    };
### 回答1: 微信小程序是现代社会中越来越受欢迎的一种应用方式,无论是企业还是个人,都可以通过开发微信小程序来实现自己的商业目标。对于刚接触微信小程序开发的人来说,需要学习相关的知识和技能,以便能够在实践中开发高质量的微信小程序。 《微信小程序开发案例教程慕课版pdf》是一本非常有用的开发指南,通过讲解多个实际的案例,介绍了微信小程序开发中的关键概念、技术和工具。这本书可以帮助读者熟悉微信小程序的开发流程和相关技术,从而提高开发速度和质量。 从内容上看,这本书有以下几个方面的优势: 1.案例丰富:《微信小程序开发案例教程慕课版pdf》中介绍了多个实际的案例,如点餐系统、电商平台、文化衫设计等,每个案例都包含了具体的设计和实现过程,让读者能够全面了解微信小程序开发的各个方面。 2.简明易懂:本书的语言简洁明了,注重讲解技术概念和实现步骤,同时也包含了大量的图例和代码示例,让读者更容易理解和运用所学知识。 3.实战强化:每个案例中都包含了一些典型的问题和解决方案,读者可以对照自己的实际开发需求,学习如何利用微信小程序开发解决实际问题。 总的来说,《微信小程序开发案例教程慕课版pdf》是一本非常实用的开发指南,可以帮助有志于学习微信小程序开发的人迅速入门并掌握相关技能。无论是自学还是参加培训,都可以通过这本书来提高自己的学习效率和开发水平。 ### 回答2: 微信小程序是一款非常流行的手机应用程序。它可提供以下服务:免费聊天、支付、分享、地图等功能,是运营商和用户之间进行沟通的最佳桥梁。微信小程序开发案例教程慕课版pdf是一份非常详细的小程序开发教程,可以帮助开发者更好地掌握微信小程序的开发技巧。 首先,《微信小程序开发案例教程慕课版pdf》包含了基础概念与框架的教学,可以帮助开发者理解微信小程序的基本原理和开发框架。其次,该教程还涵盖了小程序开发基础、功能实现、案例分析、调试以及发布等方面。最后,《微信小程序开发案例教程慕课版pdf》还提供了许多实例代码和模板,方便学习者练习。 此外, 此教程还以案例为主,涵盖了日常生活中常用的小程序,例如:点餐、报名、商城等,以及自定义组件与动画。因此,阅读此教程可以让开发者更好地了解小程序的开发并能够自己进行一些简单的小程序的开发。 总之, 微信小程序开发案例教程慕课版pdf通俗易懂、内容详实。看完本教程,开发者可掌握微信小程序开发的基础知识和技巧,对于微信小程序的日常开发也有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值