我正在尝试在我的全局 Vue() init 中定义一个组件,并且已经成功地为该组件定义了模板,但似乎无法定义执行该模板工作的实际类。我正在使用带有 typescript 的 Vue。
import ListClubsComponent from "./components/ts/list-club";
new Vue({
el: "#app",
components: {
"list-clubs": {
template: require("./components/clubs/list-clubs.html"),
model: ListClubsComponent // This should be the class for the template
}
}
});
最佳答案
与其在全局 Vue() 组件级别定义组件模板,不如尝试在 './components/ts/list-club' 中定义它:
var ListClubsComponent = {
template : ...,
data:...
...
}
然后在全局 Vue() 组件中导入并注册整个组件:
import ListClubsComponent from "./components/ts/list-club";
new Vue({
...
components : {
'list-clubs' : ListClubsComponent
}
...
})
这也应该更容易维护,因为模板与其功能组合在一起。
更多信息请访问 https://v2.vuejs.org/v2/guide/components-registration.html#Local-Registration
关于javascript - Vue 使用来自 Vue() 的模板和脚本定义组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59182893/