在laravel 5.6中导入vue包的核心方法是什么?它带有vue和bootstrap预安装。我看到它们都是从公共目录中的app.js编译的,但我可以弄清楚如何导入https://github.com/moreta/vue-search-select并使用它。在我尝试自己导入之后:
错误:
ncaught TypeError: Vue.component is not a function
在线:
Vue.component('search-user', __webpack_require__(42));
到现在为止我试过这个:
资产/ JS / bootstrap.js:
import { BasicSelect } from 'vue-search-select';
window.BasicSelect = BasicSelect;
资产/ JS / app.js:
require('./bootstrap');
window.Vue = require('vue');
window.Vue = require('vue-search-select');
Vue.component('search-user', require('./components/SearchUser.vue'));
var app = new Vue({
el: '#app'
})
成分</ P>
<template>
<basic-select :options="options"
:selected-option="item"
placeholder="select item"
@select="onSelect">
</basic-select>
</template>
<script>
export default {
data() {
return {
keywords: null,
options: []
};
},
watch: {
keywords(after, before) {
if (this.keywords.length > 0)
this.fetch();
}
},
methods: {
fetch() {
axios.get('/api/search', {params: {keywords: this.keywords}})
.then(response => this.options = response.data)
.catch(error => {
});
},
onSelect (item) {
this.item = item
},
reset () {
this.item = {}
},
selectOption () {
// select option from parent component
this.item = this.options[0]
},
components: {
BasicSelect
}
}
}
</script>
我跑了:npm install和npm run watch:
"devDependencies": {
"ajv": "^6.0.0",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"popper.js": "^1.12",
"uikit": "^3.0.0-beta.35",
"vue": "^2.5.7",
"vue-search-select": "^2.5.0"
},
"dependencies": {
"axios": "^0.17.1",
"jquery": "^3.3.1"
}
答案 0 :(得分:1)
我认为简单会做
import { BasicSelect } from 'vue-search-select';
export default {
data() {
return {
keywords: null,
options: [],
item: null
};
},
...
然后在您的组件中,您可以导入最需要的内容:
video.addEventListener("timeupdate", function(){
// check whether we have passed 5 minutes,
// current time is given in seconds
if(this.currentTime >= 10) {
//do something
document.getElementById("mainvideo").style.height='400px';
}
});
答案 1 :(得分:0)
一个缺少细节的东西欺骗了我,您需要注册这样的组件,否则找不到它:
components: {
ModelSelect,
BasicSelect
},