# uni-app中组件的创建

在uni-app中,可以通过创建一个后缀名为vue的文件,即创建一个组件成功,其他组件可以将该组件通过impot的方式导入,在通过components进行注册即可

  • 创建login组件,在component中创建login目录,然后新建login.vue文件

    <template>
    	<view>
    		这是一个自定义组件
    	</view>
    </template>
    
    <script>
    </script>
    
    <style>
    </style>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
  • 在其他组件中导入该组件并注册

    import login from "@/components/test/test.vue"
    
    1
  • 注册组件

    components: {test}
    
    1
  • 使用组件

    <test></test>
    
    1
上次更新: 2021/2/22 上午10:53:04