-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
33 lines (30 loc) · 1.06 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Vue from "vue";
Vue.directive("demo-widget", {
bind: async (element, binding) => {
const res = await fetch(
"https://jdata.azurewebsites.net/api/files/FoodItem.json"
);
const data = await res.json();
element.innerHTML =
"<h4>Hi I'm v-demo-widget, this is data I load : </h4>" +
data.map(({ imgUrl, name }) => {
return `<div style="display:inline-block;width:150px"><span>${name}</span><img width="150px" height="150px" src="${imgUrl}" alt=""/></div>`;
});
}
});
const dataUrl = "https://jdata.azurewebsites.net/api/files/cmsdemo.json";
Vue.component("cms-subscriber", async (resolve, reject) => {
const res = await fetch(dataUrl);
document.querySelector(".spinner").style.display = "none";
const data = await res.json();
resolve({
template: `<div style="padding:1em">
<h3>Content load from : <a href="${dataUrl}">${dataUrl}</a></h3>
<h3>The content is ...</h3>
<div style="padding:1em">${data.content}</div>
</div>`
});
});
new Vue({
el: "#app"
});