随笔 - 750  文章 - 1  评论 - 107  阅读 - 34万

[转]VUE 组件化开发

内容比较多,直接上代码:

src\components\06.MyHeader\MyHeader.vue

复制代码
<template>
    <div class="header-container" :style="{ background: bgcolor,color: color }">
        {{title || 'Header 组件'}}
    </div>
</template>

<script>
    export default{
        name: 'MyHeader',
        props:['title','color','bgcolor']
    }
</script>

<style type="less" scoped>
    .header-container{
        height: 45px;
        background-color: #00f;
        color:#fff;
        text-align: center;
        line-height: 45px;
        position: fixed;
        top:0;
        left:0;
        width: 100%;
        z-index: 999;
    }
</style>
复制代码
复制代码
<template>
    <div class="app-container">
        <h1>App根组件</h1>

        <hr />
    
        <MyHeader title="黑马程序员" bgcolor="#ccc" color="#f00"></MyHeader>
    </div>
</template>

<script>
import MyHeader from './06.MyHeader/MyHeader.vue'

    export default{
        name:'MyApp',
        components:{
            MyHeader
        }
    }
</script>

<style lang="less" scoped>
    .app-container{
        margin-top:45px;
    }

</style>
复制代码
import { createApp } from 'vue'
import App from './components/App.vue'

const app = createApp(App)

app.mount('#app')
复制代码
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <link rel="icon" href="/favicon.ico" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Vite App</title>
</head>
<body>
  <div id="app">

  </div>
  <script type="module" src="/src/main.js"></script>
</body>
</html>
复制代码

 

posted on   z5337  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示