Load news from json
parent
cf1a9838d6
commit
b8a283e95a
38
app.vue
38
app.vue
|
@ -6,15 +6,13 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import EventBus from '@/layouts/AppEventBus';
|
import EventBus from '@/layouts/AppEventBus';
|
||||||
import NewsService from '@/service/NewsService';
|
import News from '@/assets/data/news.json';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
themeChangeListener: null,
|
themeChangeListener: null,
|
||||||
newsActivate: null,
|
newsActivate: null,
|
||||||
newsService: null,
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
storageKey: 'primevue',
|
|
||||||
layout: 'custom'
|
layout: 'custom'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -30,27 +28,23 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
this.newsService = new NewsService();
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
/*this.newsActivate = () => {
|
this.newsActivate = () => {
|
||||||
this.newsService.fetchNews().then((data) => {
|
this.$appState.announcement = News;
|
||||||
this.$appState.announcement = data;
|
const itemString = localStorage.getItem(this.$appState.storageKey);
|
||||||
|
|
||||||
const itemString = localStorage.getItem(this.storageKey);
|
if (itemString) {
|
||||||
|
const item = JSON.parse(itemString);
|
||||||
|
|
||||||
if (itemString) {
|
if (!item.hiddenNews || item.hiddenNews !== News.id)
|
||||||
const item = JSON.parse(itemString);
|
|
||||||
|
|
||||||
if (item.hiddenNews && item.hiddenNews !== data.id) {
|
|
||||||
this.$appState.newsActive = true;
|
|
||||||
} else this.$appState.newsActive = false;
|
|
||||||
} else {
|
|
||||||
this.$appState.newsActive = true;
|
this.$appState.newsActive = true;
|
||||||
}
|
|
||||||
});
|
else this.$appState.newsActive = false;
|
||||||
};*/
|
}
|
||||||
|
else {
|
||||||
|
this.$appState.newsActive = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.themeChangeListener = (event) => {
|
this.themeChangeListener = (event) => {
|
||||||
const elementId = 'theme-link';
|
const elementId = 'theme-link';
|
||||||
|
@ -71,11 +65,11 @@ export default {
|
||||||
};
|
};
|
||||||
|
|
||||||
EventBus.on('theme-change', this.themeChangeListener);
|
EventBus.on('theme-change', this.themeChangeListener);
|
||||||
//EventBus.on('news-activate', this.newsActivate);
|
EventBus.on('news-activate', this.newsActivate);
|
||||||
},
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
EventBus.off('theme-change', this.themeChangeListener);
|
EventBus.off('theme-change', this.themeChangeListener);
|
||||||
//EventBus.off('news-activate', this.newsActivate);
|
EventBus.off('news-activate', this.newsActivate);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"id": 30,
|
||||||
|
"content": "Introducing the all-new Apollo Vite Template",
|
||||||
|
"linkText": "View Demo",
|
||||||
|
"linkHref": "https://www.primefaces.org/apollo-vue",
|
||||||
|
"backgroundStyle": "background-color:#4f8ff7",
|
||||||
|
"textStyle": "color:#ffffff;font-weight:500",
|
||||||
|
"linkStyle": "color:#ffffff;font-weight:700;text-decoration: underline;"
|
||||||
|
}
|
|
@ -15,14 +15,8 @@
|
||||||
import EventBus from '@/layouts/AppEventBus';
|
import EventBus from '@/layouts/AppEventBus';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
storageKey: 'primevue',
|
|
||||||
hovered: false
|
|
||||||
};
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
//EventBus.emit('news-activate');
|
EventBus.emit('news-activate');
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onClose() {
|
onClose() {
|
||||||
|
@ -32,7 +26,7 @@ export default {
|
||||||
hiddenNews: this.$appState.announcement.id
|
hiddenNews: this.$appState.announcement.id
|
||||||
};
|
};
|
||||||
|
|
||||||
localStorage.setItem(this.storageKey, JSON.stringify(item));
|
localStorage.setItem(this.$appState.storageKey, JSON.stringify(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
const $appState = {
|
const $appState = {
|
||||||
install: (Vue, options) => {
|
install: (Vue, options) => {
|
||||||
Vue.config.globalProperties.$appState = reactive({ theme: 'lara-light-blue', darkTheme: false, codeSandbox: false, sourceType: 'options-api', newsActive: false, announcement: {} });
|
Vue.config.globalProperties.$appState = reactive({
|
||||||
|
theme: 'lara-light-blue',
|
||||||
|
darkTheme: false,
|
||||||
|
codeSandbox: false,
|
||||||
|
sourceType: 'options-api',
|
||||||
|
newsActive: true,
|
||||||
|
announcement: {},
|
||||||
|
storageKey: 'primevue'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
export default class NewsService {
|
|
||||||
fetchNews() {
|
|
||||||
return fetch('https://www.primefaces.org/cdn/news/primevue.json', { cache: 'no-store', mode: 'no-cors' }).then((res) => res.json());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue