<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
</div>
<script src="https://mirrors.idiyrom.com/web/js/vue.mini.js"></script>
<script src="https://mirrors.idiyrom.com/web/js/vue-router.js"></script>
<script>
Vue.component("Test", {
data() {
return {
}
},
template: `
<div class="Test">
我是测试组件1
</div>`
});
Vue.component("Test2", {
data() {
return {
}
},
template: `
<div class="Test2">
我是测试组件2
</div>`
});
let App = {
data() {
return {
}
},
template: `
<div>
<input type="text" ref="aa">
<Test ref="bb"></Test>
<Test2 ref="cc"></Test2>
</div>`,
mounted() {
//获取焦点
//this.$refs.aa 获取原始DOM
this.$refs.aa.focus();
console.log(this.$refs.bb.$parent); //获取父组件
console.log(this.$refs.bb.$root); //获取根组件
console.log(this.$children);
}
};
new Vue({
el: '#app',
data() {
return {
}
},
template: `<App></App>`,
components: {
App
},
});
</script>
</body>
</html>