Vue技术18.4 VueComponent
2023-09-27 14:26:24 时间
<!DOCTYPE html>
<html>
<head>
<mata charset="UTF-8" />
<title>VueComponent</title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!--
关于VueComponent:
1.school组件本质是一个名为VueComponent的构造函数,且不是程序员定义的,是Vue.extend生成的。
2.我妈只需要写<school/>或<school></school>,Vue解析时会帮我们创建school组件的实例对象。
即Vue帮我们执行的:new VueComponent(options).
3.特别注意:每次调用Vue.extend返回的都是一个全新的VueComponent
4.关于this指向:
(1)组件配置中:
data函数、methods中的函数、watch中的函数、computed中的函数 它们的this均是【VueComponent实例对象】。
(2)new Vue()配置中:
data函数、methods中的函数、watch中的函数、computed中的函数 它们的this均是【Vue实例对象】
5.VueComponent的实例对象,以后简称vc(也可称之为:组件实例对象)
Vue的实例对象,以后简称vm.
-->
<!-- 准备好一个容器 -->
<div id="root">
<school></school>
<hello></hello>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false
//定义school组件
const school = Vue.extend({
template:`
<div>
<h2>学校名称:{{name}}</h2>
<h2>学校地址:{{address}}</h2>
<button @click="showName">点我提示学校名</button>
</div>
`,
data(){
return {
name:'尚硅谷',
address:'北京'
}
},
methods: {
showName(){
console.log('showName', this)
}
},
})
//定义hello组件
const hello = Vue.extend({
template:`<h2>{{msg}}</h2>`,
data(){
return {
msg:'你好啊'
}
}
})
new Vue({
el:'#root',
//注册组件(局部注册)
components:{
school,hello
}
})
</script>
</html>
相关文章
- 前端技术栈-ES6、Vue、ElementUI,以及Vue脚手架快速构建前端项目
- Vue 中为什么要有nextTick?
- 8分钟为你详解React、Angular、Vue三大前端技术
- 【转】vue技术分享-你可能不知道的7个秘密
- VUE , 表单中如何用获取接口数据的select
- vue组件定义方式,vue父子组件间的传值
- Vue技术18.3组件的嵌套
- Vue技术18.2几个注意点
- Vue技术17.3总结生命周期
- Vue技术17.1引出生命周期
- Vue技术15.5v-pre指令
- Vue技术15.4v-once指令
- Vue技术10.绑定样式
- Vue技术9.5姓名案例_watch实现
- Vue技术9.4
- Vue技术7.3键盘事件
- Vue技术3.数据绑定
- vue自定义指令clickoutside扩展--多个元素的并集作为inside
- AntDesign-React与VUE有点不一样,第一篇深入了解React的概念之一:JSX
- vue-d2admin前端axio异步请求详情
- 场景类:vue自制表单验证
- vue拖拽功能,提高你的开发效率
- vue 自定义i标签image
- 【Vue 开发实战】生态篇 # 16:如何在Vue中使用Vuex
- 解密Vue SSR
- new Vue 发生了什么
- Vue生命周期深入
- vue——统一配置axios的baseUrl和所有请求的路径