console
var app = new Vue({
el: '#app',
data() {
return {
jsonVal: "",
strObj: []
}
},
methods: {
toObj () {
let fixObj = JSON.parse(this.jsonVal)
for (i in fixObj) {
if (typeof fixObj[i] === 'string') {
fixObj[i] = `'${fixObj[i]}'`
}
this.strObj.push({
label: i,
val: fixObj[i]
})
}
}
},
created() {
}
});
<div id="app">
<template>
<input v-model="jsonVal"></input>
<button @click="toObj">转</button>
<template>
<div v-for="item in strObj">
<span>{{item.label}}: </span>
<span>{{item.val}},</span>
</div>
</template>
</template>
</div>