安装依赖

npm install downloadjs

使用范例

<template>
  <div style="margin:20px">
    <button @click="downloadText">下载文本——“{{ text }}”</button>
  </div>
</template>

<script>
import download from "downloadjs";
export default {
  methods: {
    downloadText() {
      this.fileName = "点击下载文本后生成的txt文件.txt";
      download(this.text, this.fileName, "text/plain");
    },
  },
  data() {
    return {
      text: "我爱你,中国!",
      fileName: "",
    };
  },
};
</script>

更多功能

详见官网
http://danml.com/download.html#Download

Logo

前往低代码交流专区

更多推荐