[Vuejs]-How do I use outsourced and editable scripts in Nuxt.js?

0👍

Like you do, or if you try to import your js file with your data like import { folderGroups, folderPermissions} from './my-outsourced-script.js, you cannot change the file without rebuild your nuxt app.

Try to build with your file as below:

{
"folderGroups": [
    your datas
  ],
"folderPermissions": [
    your datas
  ]
}

And dynamic import in your component:

data() {
  folderGroups: [],
  folderPermissions: []
},
mounted() {
  this.$http.get('/js/my-outsourced-script.json').then((response) => { // no need `assets`
    console.log(response.body)
    this.folderGroups = response.body.folderGroups
    this.folderPermissions = response.body.folderPermissions
  }, function (error) {
    console.log(error.statusText)
  })
}

Leave a comment