我試圖使用vue-instant組件作爲子組件。我不知道如何添加沒有定義的組件,或者也許我的問題是在webpack配置中忽略node_modules,因爲缺少類型?下面是我有:Vue with Typescript - 使用沒有定義的組件
SingleUserSearch.vue(我的自定義組件):
<template>
<div class="input-group">
<vue-instant
v-model="value"
@input="changed"
:suggestions="suggestions"
name="customName"
placeholder="custom placeholder"
type="google"></vue-instant>
</div>
</template>
<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import axios from "axios";
import VueInstant from 'vue-instant'
let vueInstantComponent : Vue.Component = VueInstant;
@Component({
components: {
'vue-instant': vueInstantComponent
}
})
export default class SingleUserSearch extends Vue {
value:string="";
suggestions : Array<string> = []
async changed() {
var that = this
this.suggestions = []
let response = await axios.get('https://api.themoviedb.org/3/search/movie?api_key=342d3061b70d2747a1e159ae9a7e9a36&query=' + this.value);
alert(response);
}
}
</script>
然後我用的WebPack沒有困難編譯我的代碼。當我嘗試在頁面上測試代碼時,我得到:
[Vue warn]:裝載組件失敗:模板或渲染函數未定義爲 。在
---> 發現在腳本\ VUE \組件
\ SingleUserSearch.vue
webpack.config.js
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './scripts/vue/main.ts',
output: {
path: path.resolve('./scripts/build/'),
filename: 'app.js'
},
module: {
loaders: [
{
test: /\.tsx?$/,
loader: 'ts-loader?' + JSON.stringify({
transpileOnly: true
})
},
{
test: /\.vue$/,
loader:'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['es2015','stage-0','stage-1','stage-2','stage-3']
}
}
]
},
resolve: {
extensions: ['.js', '.vue'],
alias: {
'vue': path.resolve('./node_modules/vue/dist/vue.esm.js')
}
},
stats: {
colors: true
},
devtool: 'source-map'
};