1. JSON.parse()用于从一个字符串中解析出json对象
<!--作者:zhangfan
页面名称:JSON.parse()、JSON.stringify()使用方法-->
<template>
<div id="product-list-one">
<button @click="jsonParse()">执行jsonParse</button>
</div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
export default {
data() {
return {
url: '{"name":"zhangsan","age":"28"}'
};
},
computed: {},
methods: {
jsonParse() {
console.log(this.url);
console.log(JSON.parse(this.url));
}
}
};
</script>
<style scoped>
</style>
2. JSON.stringify()用于从一个对象解析出字符串
<!--作者:zhangfan
页面名称:JSON.parse()、JSON.stringify()使用方法-->
<template>
<div id="product-list-one">
<button @click="jsonStringify()">执行jsonStringify</button>
</div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
export default {
data() {
return {
url: {
name: "zhangsan",
age: "28"
}
};
},
computed: {},
methods: {
jsonStringify() {
console.log(this.url);
console.log(JSON.stringify(this.url));
}
}
};
</script>
<style scoped>
</style>