SoFunction
Updated on 2025-04-04

Vue implements the function of generating local Json files

Vue generates local Json file function

Operation steps

First, you need to introduce a JS file

Notice! !

You must refer to components and components you define

</template>
 
<div >
	<button @click="download">download</button>
</div>
 
</template>
 
<script src="/ajax/libs//2.0.5/"></script>
<script>
	export default {
		name: "Mapview",
 
		data() {
			retrun {
				positionList: [123, 123]
			}
 
		},
		methods: {
			download() {
				var content = ({
					jiedao: ,
				})
 
				var blob = new Blob([content], {
					type: "text/plain;charset=utf-8"
				});
				(blob)
				saveAs(blob, "jiedao_8hou.json");
			},
		}
	}
</script>

After clicking the button, put the data you want to store in an array. Through this method, you can download a .json file on the web page. The data in this .json file is the data you wrote in by yourself

Vue exports JSON format configuration file

npm install file-saver package

npm install file-saver --save

Reference plus configuration

import FileSaver from 'file-saver'
// Method in js to export the obtained data into JSON formatdownDeviceProfiles() {
    getData(`/deviceProfile/${}`, {},
         (response) => {
            const blob = new Blob([(response, null, 2)], {
            type: 'application/json'
        })
        (blob, )
    })
},

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.