I have been attempting to access a YAML file from my local directory. While I am able to read the file, the data within it appears to be undefined.
The error message that I am encountering is as follows:
https://i.sstatic.net/yXC0H.png
Here is an example of how the data in the file is structured:
userName: myusername
options :
displayTime : true
displayGreating : true
fruit:
-apple
-orange
My code indicates that 'myusername' is not defined. What could this mean?
This is how I currently load the YAML file:
<template>
<div>
{{this.dataNotWorkingNow}}
</div>
</template>
<script>
import yaml from "js-yaml";
import fs from "fs";
import config from "./config.yml";
export default {
data() {
return {
dataNotWorkingNow: []
};
},
created() {
fs.readFile(config, "utf8", function(e, data) {
var file;
if (e) {
console.log("config.yml not found.");
} else {
file = yaml.safeLoad(data, "utf8");
if (file.options["displayGreating"]) {
console.log("hello " + file.userName);
}
if (file.options["displayTime"]) {
console.log("the time is: " + new Date());
}
}
});
}
};
</script>
Can someone advise me on how to properly retrieve and load data from a local file?