gpt4 book ai didi

vue.js - 在 laravel 中导入 vue 包

转载 作者:搜寻专家 更新时间:2023-10-30 22:43:24 25 4
gpt4 key购买 nike

在 laravel 5.6 中导入 vue 包的正确方法是什么?它预装了 vue 和 bootstrap。我看到它们都是从公共(public)目录在 app.js 中编译的,但我可以弄清楚如何导入 https://github.com/moreta/vue-search-select并使用它。在我尝试自己导入之后:

错误:

ncaught TypeError: Vue.component is not a function

At line:

Vue.component('search-user', __webpack_require__(42));

到目前为止我试过这个:

Assets /js/bootstrap.js:

import { BasicSelect } from 'vue-search-select';
window.BasicSelect = BasicSelect;

Assets /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'
})

组件

<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"
}

最佳答案

我认为简单的就可以了

window.Vue = require('vue');
require('vue-search-select');

然后在您的组件中,您可以在顶部导入您需要的内容:

import { BasicSelect } from 'vue-search-select';

export default {
data() {
return {
keywords: null,
options: [],
item: null
};
},
...

关于vue.js - 在 laravel 中导入 vue 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48925886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com