Why is the checkList type printed as object?

<template>
  <div>
        <ul>
            <li class="bookItem" v-for="item in bookList" :key="item.id" style="text-align: left;">
               <el-checkbox v-model="item.checked" @change="handleChecked(item)">
                <img class="bookImg" :src="item.book_url" style="width: 100px; height: 100px;">
                <h3>{{item.book_title}}</h3>
                <span class="price">{{item.book_price}}</span>
                <div @click.stop="func">
                      <el-input-number v-model="item.num" size="small" @change="handleChange" :min="1"></el-input-number> 
                  </div>
                </div>
            </el-checkbox>
            </li>
        </ul>
      </keep-alive>
      
      <div class="cart">
          <span></span>
          <span class="highLight">{{mount}}</span>
          <span></span>
          <el-button type="primary" @click.native="onOrder" :disabled="disable"><router-link :to="{name:"Money",params:{data:this.sel}}"></router-link></el-button>
          <!-- <el-button type="primary" @click.stop="onOrder"><router-link to="/book/bookMoney"></router-link></el-button> -->
      </div>
  </div>
 </template>
<script> 
export default {
  data () {
    return {
    checkAll: false,
    isIndeterminate: true,
    breadCrumbList: [],
    bookList: [],
    radio: "0",
    checkList: [],
    num: 1,
    mount: 0,
    total: 0,
    sel: [],
    clickFlag: false,
    disable: true
    }
  },
  mounted () {
    window.localStorage.checkList = "[object Object]"
    this.bookList = [{
    id: "0",
    book_url: require("../assets/images/book1.jpg"),
    book_title: "",
    book_price: "39",
    num: 0,
    checked: false
    },{
    id: "1",
    book_url: require("../assets/images/book2.jpg"),
    book_title: "",
    book_price: "45",
    num: 0,
    checked: false
    },{
    id: "2",
    book_url: require("../assets/images/book3.jpg"),
    book_title: "",
    book_price: "59",
    num: 0,
    checked: false
    }]
  },
  methods: {
    func () {
    },
    handleChecked (val) {
      //checkboxid
      console.log(typeof this.checkList) //object?
      if (this.checkList.indexOf(val.id) == -1)
        this.checkList.push(val.id)
      //
      if (this.checkList.length > 0)
        this.disable = false

      //checkbox
      if (val.checked === true) {
        console.log(66)
        this.mount += Number(val.num)
      } else {
        console.log(this.checkList)
         console.log(typeof this.checkList)
        // this.checkList.remove(val.id)
        this.mount -= Number(val.num)
      }
      //checkboxidlocalStorage
      window.localStorage.setItem("checkList",JSON.stringify(this.checkList))
    },
  
</script>

Oct.10,2021

Array is object, isn't it? What's the problem. There is no data type called Array, and localStorage can only save strings, so it is possible to convert JSON.stringify to string and JSON.parse to object.


arrays use typeof to type out object . To check whether the object is an array, you can use Array.isArray

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5fca0-4585b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5fca0-4585b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?