Pre*_*thi 5 javascript mvvm viewmodel vue.js
Javascript代码:
var main = new Vue({
el: "#main",
data: {
currentView: "top",
},
});
var topComponent = Vue.component('top', Vue.extend({
template: "#top",
}));
Run Code Online (Sandbox Code Playgroud)
现在,当我访问main.currentView时,我得到"顶部".但是这个字符串'top',我如何获得组件topComponent?
Mig*_*ell 10
来自VueJS指南
尽管存在道具和事件,但有时您可能仍需要直接访问JavaScript中的子组件.要实现此目的,您必须使用参考ID为子组件分配
ref.例如:
var parent = new Vue({ el: '#parent' })
// access child component instance
var child = parent.$refs.profileRun Code Online (Sandbox Code Playgroud)
<div id="parent">
<user-profile ref="profile"></user-profile>
</div>Run Code Online (Sandbox Code Playgroud)
这很简单。您可以topComponent使用Vue.component.
var topComponent = Vue.component('top');
Run Code Online (Sandbox Code Playgroud)
现在你有了topComponent,你可以用它的方法做很多事情。
cid
options
super
extend
directive
filter
partial
transition
component
Run Code Online (Sandbox Code Playgroud)
您可能想查看这个示例:
它在 html 中使用v-view指令,该指令采用字符串来更改显示的视图模型。一些甜蜜的转变也在发生。
来自: https: //github.com/yyx990803/vue/blob/master/test/function/fixtures/routing.html
| 归档时间: |
|
| 查看次数: |
21086 次 |
| 最近记录: |