VUE 判斷數據類型


1、方法

<!--
 * @Descripttion: 類型判斷
 * @version: 0.0.1
 * @Author: PengShuai
 * @Date: 2022年04月29日11:21:14
 * @LastEditors: PengShuai
 * @LastEditTime: 2022年04月29日11:21:14
-->
const typeOf = data => {
  let type = Object.prototype.toString.call(data);
  if (type === "[object String]") {
    type = "String";
  } else if (type === "[object Number]") {
    type = "Number";
  } else if (type === "[object Null]") {
    type = "Null";
  } else if (type === "[object Boolean]") {
    type = "Boolean";
  } else if (type === "[object Array]") {
    type = "Array";
  } else if (type === "[object Object]") {
    type = "Object";
  } else {
    type = "未進行判斷的類型:" + type;
  }
  return type;
};

2、例


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM