我刚刚安装了vue instant,为搜索提供了一个自动建议,并获得了如下示例代码
https://jsfiddle.net/santiblanko/dqo6vr57/
我的问题是如何将组件'vue-instant': VueInstant.VueInstant
移动到一个新的Vue组件上,比如:
Vue.component('vue-instant-component', {
//vue-instant
}
我试过这样的方法:
Vue.component('vue-instant', {
data: {
value: '',
suggestionAttribute: 'original_title',
suggestions: [],
selectedEvent: ""
},
methods: {
clickInput: function() {
this.selectedEvent = 'click input'
},
clickButton: function() {
this.selectedEvent = 'click button'
},
selected: function() {
this.selectedEvent = 'selection changed'
},
enter: function() {
this.selectedEvent = 'enter'
},
keyUp: function() {
this.selectedEvent = 'keyup pressed'
},
keyDown: function() {
this.selectedEvent = 'keyDown pressed'
},
keyRight: function() {
this.selectedEvent = 'keyRight pressed'
},
clear: function() {
this.selectedEvent = 'clear input'
},
escape: function() {
this.selectedEvent = 'escape'
},
changed: function() {
var that = this;
this.suggestions = [];
axios.get('https://api.themoviedb.org/3/search/movie?api_key=342d3061b70d2747a1e159ae9a7e9a36&query=' + this.value)
.then(function(response) {
response.data.results.forEach(function(a) {
that.suggestions.push(a)
});
});
}
}
})
但它不起作用