Implementieren Sie eine JSON-formatierte Anzeige in Vue

Konvertieren Sie ein JSON-Objekt in ein eingerücktes JSON-String-Format

Original

 Darstellungen

 

<template>
  <div class='content'>
    <el-button type="primary" @click="clickFormat">格式化JSON</el-button>
    <el-input v-model="jsonStr" autosize type="textarea" placeholder="Please input" />
  </div>
</template>

<script>

export default {
  name: "manage",
  data() {
    return {
      jsonStr: ''
    }
  },
  methods:{
    clickFormat(){
  // 1、JSON.parse:把JSON字符串转换为JSON对象
  // 2、JSON.stringify:把JSON对象 转换为 有缩进的 JSON字符串格式
  this.jsonStr = JSON.stringify(JSON.parse(this.jsonStr), null, '\t')
}
  }
}
</script>

<style scoped>

</style>

Acho que você gosta

Origin blog.csdn.net/weixin_45294459/article/details/128145479
Recomendado
Clasificación