localStorage push数组并去重

     // 选择关键字
      handleKeyword(item) {
        const keyword = []
        keyword.push({
          ...item,
          code: '{' + item.code + '}'
        })
        const getLocalexample = JSON.parse(localStorage.getItem('example'))
        if (getLocalexample) {
          console.log(getLocalexample)
          keyword.forEach(item => {
            getLocalexample.forEach(v => {
              if (item.name !== v.name) {
                getLocalexample.push(...keyword)
                localStorage.example = JSON.stringify([...new Set(getLocalexample)])
              }
            })
          })
        } else {
          localStorage.setItem('example', JSON.stringify(keyword))
        }
      },

 

你可能感兴趣的:(ES6,vue2.0)