I'm iterating through an array within an object. When I update an object in the array, the data updates, but, the UI doesn't
Data looks like this
projectConfig = {
files: [
lang: "ar-eg",
paths: ["/Users/omarabdelhady/Desktop/Others/test/i18n/ar-eg.json"]
]
}
HTML
<div class="col-12 files-box">
<div v-for="(file, index) in projectConfig.files" :key="file.lang">
<bdi>Lang : {{file.lang}}</bdi>
<div>
Files :
<ul class="col-12 app-list">
<li v-for="(path, i) in file.paths" :key="path">
{{getFileNameFromPath(path)}}
<i class="i-bin"
@click="deleteLang(i, index)">
</i>
</li>
</ul>
</div>
</div>
</div>
delete method
deleteLang(pathIndex, fileIndex) {
this.projectConfig.files[fileIndex].paths.splice(pathIndex, 1);
if(this.projectConfig.files[fileIndex].paths.length === 0) {
this.projectConfig.files.splice(fileIndex, 1);
}
}
I use the :key for v-for to detect changes, didn't work I tried this.$forceUpdate(), worked, but I think it is not the best solution
-- update actually the data looks like this
projectConfig = {
files: [{
lang: "ar-eg",
paths: ["/Users/omarabdelhady/Desktop/Others/test/i18n/ar-eg.json"]
}]
}
plus I'm using typescript
filesas an object. I tried your code in a fiddle (with the fix) and it worked just fine. Check it out: jsfiddle.net/9dxeh671files: [{ lang: "ar-eg", paths: ["/Users/omarabdelhady/Desktop/Others/test/i18n/ar-eg.json"] }]