npm install file-saver
<template>
<button @click="saveToFile">保存文件</button>
</template>
<script>
import { saveAs } from 'file-saver'
export default {
methods: {
saveToFile() {
const data = '测试测试测试!'
const filename = 'test.txt'
const blob = new Blob([data], { type: 'text/plain;charset=utf-8' })
saveAs(blob, filename)
}
}
}
</script>