[Vuejs]-How load specific file by path?

0๐Ÿ‘

U can use fetch for that

var vm = new Vue({
  ....
  methods: {
    loadConfig(file) {
      fetch('253.01.00.00.SD.json') //or fetch(file) if you want to fetch the given file
        .then(function(response) {
          return response.json();
        })
        .then(function(myJson) {
          console.log(JSON.stringify(myJson));
        });
    }
 }
 ....

0๐Ÿ‘

I assume that 253.01.00.00.SD.json is some file on your local directory.

import json from './253.01.00.00.SD.json'

export default{
  data(){
    return{
      ourData: json
    }
  }
 }

In the template you do something like this:

<template>
  <div>
    <div v-for="data in ourData">{{data}}</div>
  </div>
</template>

Leave a comment