npm install file-saver --save
<template>
<div class="hello">
<button @click="exportJSON">导出jsonn</button>
<button @click="exportText">导出Text</button>
</div>
</template>
<script>
import FileSaver from 'file-saver'
export default {
data () {
return {
CfgInfo: {
CAN: {
Chn: 0,
name: 'CAN通道'
},
LIN: {
Chn: 1,
name: 'LIN通道'
}
}
}
},
methods: {
exportJSON () {
const data = JSON.stringify(this.CfgInfo)
const blob = new Blob([data], {type: ''})
FileSaver.saveAs(blob, 'hahaha.json')
},
exportText () {
const textStr = 'aaaaa,bbbbbbb,cccccc'
FileSaver.saveAs(textStr, 'a.txt')
}
}
}
</script>