2021-12-25 22:28:59 +00:00
|
|
|
if (/^file:\/\/\//.test(location.href)) {
|
|
|
|
let path = './';
|
|
|
|
let orig = fetch;
|
|
|
|
window.fetch = (resource) => ((/^[^/:]*:/.test(resource)) ?
|
|
|
|
orig(resource) :
|
|
|
|
new Promise(function(resolve, reject) {
|
|
|
|
let request = new XMLHttpRequest();
|
|
|
|
|
|
|
|
let fail = (error) => {reject(error)};
|
|
|
|
['error', 'abort'].forEach((event) => { request.addEventListener(event, fail); });
|
|
|
|
|
|
|
|
let pull = (expected) => (new Promise((resolve, reject) => {
|
|
|
|
if (
|
|
|
|
request.responseType == expected ||
|
|
|
|
(expected == 'text' && !request.responseType)
|
|
|
|
)
|
|
|
|
resolve(request.response);
|
|
|
|
else
|
|
|
|
reject(request.responseType);
|
|
|
|
}));
|
|
|
|
|
|
|
|
request.addEventListener('load', () => (resolve({
|
|
|
|
arrayBuffer : () => (pull('arraybuffer')),
|
|
|
|
blob : () => (pull('blob')),
|
|
|
|
text : () => (pull('text')),
|
|
|
|
json : () => (pull('json'))
|
|
|
|
})));
|
|
|
|
request.open('GET', resource.replace(/^\//, path));
|
|
|
|
request.send();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var app = new Vue({
|
|
|
|
el: '#app',
|
|
|
|
data: {
|
|
|
|
message: 'Hello Vue!',
|
|
|
|
json: null,
|
|
|
|
hits:0
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
pretty: function(value) {
|
|
|
|
return JSON.stringify(JSON.parse(value), null, 2);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods:{
|
2021-12-25 22:39:07 +00:00
|
|
|
load() {
|
2021-12-25 22:28:59 +00:00
|
|
|
this.hits += 1
|
|
|
|
fetch("data.json")
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => (this.json = data));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
this.load()
|
|
|
|
}
|
|
|
|
});
|