import axios from 'axios';
export default {
name: 'Search',
props: {
requireType: {
type: String,
required: true,
},
},
data() {
return {
searchModal: {
select: 'weibo',
value: '',
},
require: this.requireType,
};
},
methods: {
search() {
if (this.require === 'focused') {
axios.get('./static/hotRadeFocused.json')
.then((response) => {
this.$emit('getData', response.data);
});
}
if (this.require === 'weibo') {
axios.get('./static/hotRadeWeibo.json')
.then((response) => {
this.$emit('getData', response.data);
});
}
},
},
watch: {
require: function (val) {
this.search();
},
},
beforeMount() {
this.search();
},
};
对于原始类型变量,watch可以直接监听,对于引用类型变量,采用深度监听。