-
Notifications
You must be signed in to change notification settings - Fork 2
/
SourceSelection.vue
53 lines (52 loc) · 1.67 KB
/
SourceSelection.vue
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<template>
<div>
<div class="jumbotron">
<h4>Select News Source</h4>
<select id="basicSelect" class="form-control" v-on:change="sourceChanged">
<option value="">Please select news source ...</option>
<option v-for="source in sources" v-bind:value="source.id">{{source.name}}</option>
</select>
<div v-if="source">
<h6>{{source.description}}</h6>
<a v-bind:href="source.url" class="btn btn-primary" target="_blank">Go To {{source.name}} Website</a>
</div>
</div>
</div>
</template>
<script>
define(['Vue', 'ojs/ojselectcombobox'], function (Vue) {
Vue.component('SourceSelection', {
template: template,
data: function() {
return {
sources: [],
source: ''
};
},
methods: {
sourceChanged: function(e) {
for (var i=0; i<this.sources.length; i++) {
if (this.sources[i].id == e.target.value) {
this.source = this.sources[i];
}
}
this.$emit('sourceChanged', e.target.value);
}
},
created: function () {
this.$http.get('https://newsapi.org/v1/sources?language=en')
.then(response => {
this.sources = response.data.sources;
});
},
mounted() {
$('#basicSelect').ojSelect({
optionChange: (event, ui) => {
this.$emit('sourceChanged', ui['value']);
this.source = ui['value'];
}
});
}
});
});
</script>