javascript - 如何使用 vue js 在提交时将表单数据保存在 .yml 文件中?

标签 javascript html vue.js

我正在开发一个简历生成器,我希望能够保存 将表单数据输入到 .yml 文件中,但我似乎找不到任何文章 给我一些线索。我希望一旦单击提交按钮,数据就会自动写入.yml 文件中

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<template>
    <div class="biography">
        <h2>Fill in your education information</h2>
        <label for="degree">Degree</label>
        <input id="degree"  type="text">
        <br/>
        <label for="from">From</label>
        <input id="from" type="date">
        <br/>
        <label for="to">To</label>
        <input id="to"  type="date">
        <br/>
        <button id="submit" type="submit">Submit</button>
    </div>
</template>
<script>
    export default {
        name: "Education"
    }
</script>
<style scoped>
    input {
        margin-left: 100px;
        margin-bottom: 10px;
        border: 2px;
        width: 300px;
        height: 3em;
        display: inline-block;
    }
    button {
        font-size: 16px;
        padding: 10px;
        background-color: #004d4d;
        color: white;
        border-radius: 6px;
    }
    button:active {
        background-color: #00e6e6;
    }
    label {
        position: absolute;
    }
</style>

最佳答案

如果您编写一个函数将输入值转换为表示有效 YAML 文本的字符串,则可以使用 Blob API 将其转换为文件。

作为媒体类型,请使用与您公司使用的其他 YAML 文件相同的类型(text/yaml、application/yaml、text/vnd.yaml 等),因为我们(据我所知)还没有 YAML 的标准类型文件。

要实际保存文件,您需要从该 Blob 创建一个 URL,用户可以单击下载。 (请参阅 SO 或任何 JS blob-to-url 教程中有关此问题的大量其他问题。)

如果您实际上向服务器端脚本提交表单,可能有一堆服务器库可以创建 YAML 文件,您可以将其作为表单 POST 请求的响应返回。

关于javascript - 如何使用 vue js 在提交时将表单数据保存在 .yml 文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55398048/

相关文章:

javascript - 没有匿名函数的事件处理程序

javascript - 在类更改时使用 css 制作动画

javascript - TinyMCE 的 multipart/form-data、ajax 和 textarea 问题

html - 输入框的多个背景

javascript - Vue.js动态挂载单文件组件

javascript - Vue.js 无法读取 null 的属性 'length'

javascript - Node.js 中的服务器命令(或等效命令)

javascript - data-toggle 属性如何工作? (它的API是什么?)

javascript - HTML 5 表单输入验证

javascript - 图片选择Vuejs