on centralise le setItem du localStorage, apres chaque ajax et apres le

rendu
This commit is contained in:
Christophe 2020-05-11 00:25:21 +02:00
parent 9851712bbe
commit e7f51f6bbf
2 changed files with 33 additions and 6 deletions

View file

@ -140,6 +140,19 @@ let monTableau = {
this.parPage = e; this.parPage = e;
} }
}, },
table() {
let $table = [];
$table = [
...[
{
header: this.header,
crayons: this.crayons,
},
],
...this.table,
];
localStorage.setItem('gamuTable', JSON.stringify($table));
},
}, },
methods: { methods: {
chargerJson(id) { chargerJson(id) {
@ -149,7 +162,7 @@ let monTableau = {
} else { } else {
let data = localStorage.getItem('gamuTable'); let data = localStorage.getItem('gamuTable');
data = recupJson(data); data = recupJson(data);
if (data) { if (data && data.length) {
let config = data.shift(); let config = data.shift();
this.header = config.header; this.header = config.header;
this.crayons = config.crayons; this.crayons = config.crayons;
@ -163,12 +176,11 @@ let monTableau = {
fetch(url) fetch(url)
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
localStorage.setItem('gamuTable', JSON.stringify(data));
let config = data.shift(); let config = data.shift();
this.header = config.header; this.header = config.header;
this.crayons = config.crayons; this.crayons = config.crayons;
if (parseInt(id) > 0) { if (parseInt(id) > 0) {
let i = this.table.findIndex((ligne) => ligne.id === parseInt(id)); let i = this.table.findIndex((ligne) => ligne.html.id === parseInt(id));
Vue.set(this.table, i, data[0]); Vue.set(this.table, i, data[0]);
} else { } else {
this.table = data; this.table = data;

View file

@ -1,5 +1,13 @@
"use strict"; "use strict";
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
@ -151,6 +159,14 @@ var monTableau = {
} else { } else {
this.parPage = e; this.parPage = e;
} }
},
table: function table() {
var $table = [];
$table = [{
header: this.header,
crayons: this.crayons
}].concat(_toConsumableArray(this.table));
localStorage.setItem('gamuTable', JSON.stringify($table));
} }
}, },
methods: { methods: {
@ -165,7 +181,7 @@ var monTableau = {
var data = localStorage.getItem('gamuTable'); var data = localStorage.getItem('gamuTable');
data = recupJson(data); data = recupJson(data);
if (data) { if (data && data.length) {
var config = data.shift(); var config = data.shift();
this.header = config.header; this.header = config.header;
this.crayons = config.crayons; this.crayons = config.crayons;
@ -182,14 +198,13 @@ var monTableau = {
fetch(url).then(function (response) { fetch(url).then(function (response) {
return response.json(); return response.json();
}).then(function (data) { }).then(function (data) {
localStorage.setItem('gamuTable', JSON.stringify(data));
var config = data.shift(); var config = data.shift();
_this2.header = config.header; _this2.header = config.header;
_this2.crayons = config.crayons; _this2.crayons = config.crayons;
if (parseInt(id) > 0) { if (parseInt(id) > 0) {
var i = _this2.table.findIndex(function (ligne) { var i = _this2.table.findIndex(function (ligne) {
return ligne.id === parseInt(id); return ligne.html.id === parseInt(id);
}); });
Vue.set(_this2.table, i, data[0]); Vue.set(_this2.table, i, data[0]);