美文网首页
VUE组件化开发

VUE组件化开发

作者: 小黄不头秃 | 来源:发表于2023-06-05 10:49 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 
        组件化开发思想
        组件注册
        Vue调试工具用法
        组件间数据交互
        组件插槽
        基于组件的案例
     -->

     <!-- 
         组件规范:web components
      -->
      <!-- 
          组件的注册(全局组件注册法)
          Vue.component(组件名称,{
              data:组件数据,
              template:组件模板内容
          })
       -->
       <div id="app">
           <button-counter></button-counter>
           <hello-world></hello-world>
           <hello-tom></hello-tom>
       </div>
       <script src="./vue/vue.js"></script>
       <script>
        /*
        组件注册的注意事项:
        (1)data必须是一个函数:分析函数与普通对象的对比
        (2)组件模板内容必须是单个根元素
        (3)组件模板内容可以是模板字符串
            template:`
            <div>
                <button @click="handel">点击了{{count}}次</button>
            </div>
            `
        (4)如果使用驼峰式命名组件,那么在使用组件的时候,只能在字符模板中使用驼峰式的方法使用组件,
            但是在普通标签中,必须使用短横线的方式使用组件
        **/    
           Vue.component('button-counter',{
               data:function(){
                   return {
                       count:0
                   }
               },
               template:'<button @click="handel">点击了{{count}}次</button>',
               methods:{
                   handel:function(){
                       this.count++;
                   }
               }
           });
        //    局部组件注册
        var HelloWorld = {
            data:function(){
                return {
                    msg:"hello world"
                    }
            },
            template:'<div>{{msg}}</div>'
        };
        var HelloTom = {
            data:function(){
                return {
                    msg:"hello tom"
                    }
            },
            template:'<div>{{msg}}</div>'
        };
           var vm = new Vue({
               el:"#app",
               data:{},
               methods:{},
               components:{
                   'hello-world':HelloWorld,
                   'hello-tom':HelloTom
               }
           });
       </script>
</body>
</html>

相关文章

  • Vue 学习记录二

    组件化: 动态组件 父子组件 插槽 数据共享(Vuex) Vue Router: 生命周期: Plugin 开发:...

  • 简单情况

    Vue和Angular、React都是前端框架 1、单页面框架 2、基于模块化组件化的开发模式 Vue简单 灵活 ...

  • Vue-基础语法(三)

    组件化开发 一、组件概念组件化规范:Web Components 浏览器支持不好,vue 实现了这个规范https...

  • vue项目实践后的一些体会感想

    用了vue开发网页后,一下子喜欢上了vue。vue轻量,开发可以做到很好的前后端分离、组件化和模块化。最近在给公司...

  • Vue源码阅读(二)

    组件化 vue可以使用组件化来开发,在前边介绍_createElement方法时,在对原生的tag时直接创建vno...

  • Vue单文件组件开发的基本套路--以常用的Modal模态框组件开

    在实际开发工程化vue项目时,基本都是使用单文件组件形式,即每个.vue文件都是一个组件。最基本的就是UI组件了,...

  • vue(2)

    Vue组件化开发 组件化开发的思想 组件的注册 组件间的数据交互 组件插槽的用法 Vue调试工具的用法 组件开发思...

  • React组件一

    组件化开发一 目前,前端三大框架(Vue,React,Angular)都在使用组件化的我形式进行开发。19年最火的...

  • 如何开发vue、react、angular的组件库教程

    关键词:vue,react,angular,开发,封装,ui组件,组件库,常用组件 目标:开发相应的组件库vue-...

  • vue 实现数据共享模式.

    vue 都是组件化的开发模式. 整个组件树中,组件和组件之间的关系如下图所示. 父子组件传值一般用 props &...

网友评论

      本文标题:VUE组件化开发

      本文链接:https://www.haomeiwen.com/subject/ebkpedtx.html