• vue2 手记


    vue2 手记

    Vue文档:https://cn.vuejs.org/v2/api/#provide-inject

    Vue 生命周期:https://cn.vuejs.org/v2/guide/instance.html

    vuex状态管理:https://vuex.vuejs.org/zh/

    1.简单循环

    2.数组包含某值函数.includes()

    3.获取路由

    4. 获取数据类型

    5.数据克隆

    1.简单循环

    1).

    item:定义的每一条的变量

    response.data.result:要循环的数组

    for(let item of response.data.result) {
        //用item操作每一条数据。
    }
    

    2).

    response.data.result:要循环的数组

    index:索引

    response.data.result.forEach((item, index) => {
        // 用item操作每一条数据。
    })
    

      

    2.数组包含某值函数.includes()

    [1, 2, 3].includes(2); // true
     
    [1, 2, 3].includes(4); // false
    
    [1, 2, 3].includes(3, 3); // false
     
    [1, 2, 3].includes(3, -1); // true
    

     详细:https://www.cnblogs.com/rain-in-summer/p/9792165.html

    3.获取路由

    window.document.location.pathname // 亲测
    
    this.$route.query
    
    router.split('?')[1]
    

      

    4. 获取数据类型

     1)typeof 

    typeof data // 获取数据类型(array,object)

      或

    typeof(a) //旧写法
    

     2)isNaN

    使用js自带全局函数isNaN(), isNaN()返回一个Boolean值,如下 :

    var c="hello"; //字符串
    
    isNaN(c); //返回一个true;
    
    var c=10; //数字
    
    isNaN(c);//返回一个false

    如果以上c为一个空串或是一个空格,isNaN将把c当作数字0来处理,所以检查不严谨。

    3)正则表达式

    function checkNum(input){
    
    var reg=/^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 ,判断正整数用/^[1-9]+[0-9]*]*$/
    
    var num=document.getElementById(input).value;
    
    if(!reg.test(num)){
    
            alert("请输入数字");
    
        document.getElementById(input).value="";
    
        return false;
    
        }
    
    }
    

      

    5.数据克隆

    1)

    objClone=JSON.parse(JSON.stringify(obj))
    

    2)

    function deepClone (data) {
      let type = typeof data
      let obj
      if (type === 'array') {
        obj = []
      } else if (type === 'object') {
        obj = {}
      } else {
        // 不再具有下一层次
        return data
      }
      if (type === 'array') {
        for (let i = 0, len = data.length; i < len; i++) {
          obj.push(deepClone(data[i]))
        }
      } else if (type === 'object') {
        for (const key in data) {
          if (key == 0) {
            obj = []
          }
          if (!isNaN(key)) {
            obj.push(deepClone(data[key]))
          } else {
            obj[key] = deepClone(data[key])
          }
        }
      }
      return obj
    }
    

      

    JS使用Cookie:https://www.cnblogs.com/cxscode/p/11177580.html

    Vue2技术栈归纳与精粹:https://blog.csdn.net/sinat_17775997/article/details/78913968

  • 相关阅读:
    Ajax beforeSend和complete 方法
    CLR Via CSharp读书笔记(17):委托
    linux上部署Django项目(Apache+mod_wsgi+django)
    用Apache+mod_wsgi部署python程序 作者:leven | 日期20101129 00:09:37
    VirtualBox桥接网络的简单配置,让虚拟机直接访问网络
    Django and mod_wsgi deploy example
    How to use Django with FastCGI, SCGI, or AJP¶
    Fedora 15 下编译安装apache
    Change Ubuntu Server from DHCP to a Static IP Address
    How to Verify a CentOS Linux Server is 32 Bit or 64 Bit
  • 原文地址:https://www.cnblogs.com/cxscode/p/11177150.html
Copyright © 2020-2023  润新知