Vueの3つの点es 6の知識、拡張演算子

3873 ワード

Vueの中の3つの点は異なる状況の下での意味です
  • 操作配列
  •     //          
        methods: {
          /**
           *            
           */
          iClick() {
            let iArray = ['1', '2', '3'];
            console.log(...iArray);
            //       1 2 3
          },
    
          /**
           *         
           */
          iClick3() {
            let iArray = ['1', '2', '3'];
            console.log(['0', ...iArray, '4']);
            //       ["0", "1", "2", "3", "4"]
          },
    
          /**
           *         (      )
           *         
           *               ,           ,     。
           */
          iClick8() {
            const [first, ...rest] = [1, 2, 3, 4, 5];
            console.log(first);
            //      1
            console.log([...rest]);
            //      [2, 3, 4, 5]
    
            const [one, ...last] = ["foo"];
            console.log(one);
            //     foo
            console.log([...last]);
            //     []
          },
    
          /**
           *      
           */
          iClick6() {
            // ES6    
            var arr1 = [0, 1, 2];
            var arr2 = [3, 4, 5];
            arr1.push(...arr2);
            console.log(arr1);
            //       [0, 1, 2, 3, 4, 5]
          },
    
          /**
           *      (    )
           */
          iClick7() {
            var arr1 = [0, 1, 2];
            var arr2 = [3, 4, 5];
            console.log([...arr1, ...arr2]);
            //       [0, 1, 2, 3, 4, 5]
          },
    
          /**
           *         
           */
          iClick9() {
            let iString = 'woshizhongguoren';
            console.log([...iString]);
            //       ["w", "o", "s", "h", "i", "z", "h", "o", "n", "g", "g", "u", "o", "r", "e", "n"]
          },
    
          /**
           * Map   Set   , Generator   
           */
          iClick10() {
            let map = new Map([
              [1, 'one'],
              [2, 'two'],
              [3, 'three'],
            ]);
            let arr = [...map.keys()];
            console.log(arr);
            //       [1, 2, 3]
    
          },
    
    
          /**
           *       
           *          
           */
          iClick4() {
            let iArray = ['1', '2', '3'];
            //      ,     
            this.hanshu(...iArray);
          },
          hanshu(...iArray) {
            let ooo = 1;
            console.log(...iArray);
            //       1 2 3
          },
          
          /**
           *      
           */
          iClick5() {
            let iArray = [1, 2, 3, 99, 44, 66, 21, 85, 77];
            let ooo = Math.max(...iArray);
            console.log(ooo);
            //       99
          },
    
          /**
           *      iterator     ,       ,    。
           */
          iClick11() {
            let obj = {
              name: 'zhh',
              age: '20'
            }
            console.log([...obj]);
          },
    
        }
    
    
  • 操作対象
  •  methods: {
    
          /**
           *       
           */
          method3() {
            let a = {age: 18, id: 10};
            //   name   ,     
            let c = {name: 'zhh', ...a};
            console.log(c);
            //        {name: "zhh", age: 18, id: 10}
    
          },
    
          /**
           *       
           */
          method2() {
            let a = {name: 'zhh', age: 18, id: 10};
            //   a,    name:zhh1,  a  name       
            let c = {...a, name: 'zhh1'};
            console.log(c);
            //       {name: "zhh1", age: 18, id: 10}
    
          },
    
          /**
           *       (        )
           */
          method1() {
            let a = {name: 'zhh', age: 18, id: 10};
            let {name, ...c} = a;
            console.log(name, c);
            //       zhh {age: 18, id: 10}
          },
    
    
    
        }
    
  • ...mapStateと...mapActionsは...の拡張は、stateの変数またはメソッドを抽出して展開するmapStateとmapActionsの簡便な使い方
  • である.
  • 参考記事:
  • https://blog.csdn.net/zhaihaohao1/article/details/89468444