首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cssjshtml vue.js 组件嵌套demo

cssjshtml vue.js 组件嵌套demo

作者头像
葫芦
发布2019-04-17 15:17:31
1.9K0
发布2019-04-17 15:17:31
举报
文章被收录于专栏:葫芦葫芦

components/Users.vue

<template>

  <div class="users">
    <h1>hello users</h1>
    <ul>
      <li v-for="user in users"
      v-on:click="user.show=!user.show">
       <h2>{{user.name}}</h2>
        <h3 v-show="user.show">{{user.position}}</h3>
      </li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: "users",
    data() {
      return {users:[
          {name:"brownwang",position:"运维开发",show:false},
          {name:"brownwang",position:"运维开发",show:false},

          {name:"brownwang",position:"运维开发",show:false},
          {name:"brownwang",position:"运维开发",show:false},
          {name:"brownwang",position:"运维开发",show:false}]
      }
    }
  }
</script>

<style scoped>
.users{
  width:100%;
  max-width:1200px;
  margin:40px auto;
  padding:0 20px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
  ul{
    display:flex;
    flex-wrap:wrap;
    list-style-type:none;
    padding:0;
  }
  li{
    flex-grow:1;
    flex-basis:200px;
    text-align:center;
    padding:30px;
    border:1px solid #222;
    margin:10px;
  }
</style>

components/Header.vue

<template>
 <header>
   <h1>{{title}}</h1>
 </header>
</template>

<script>
export default {
  name: 'app-header',
  data () {
    return {
      title:'Vue.js Demo'
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  header{
    background:lightgreen;
    padding:10px;
  }
  h1{
    color:#222;
    text-align:center;
  }
</style>

components/Footer.vue

<template>
 <footer>
   <p>{{copyright}}</p>
 </footer>
</template>

<script>
export default {
  name: 'app-footer',
  data () {
    return {
      copyright:'Copyright 2019 Vue Demo'
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  footer{
    background:#222;
    padding:6px;
  }
  p{
    color:lightgreen;
    text-align:center;
  }
</style>

App.vue

<!-- 1模板:html结构 -->
<template>
  <div id="app">
    <app-header></app-header>
    <users></users>
    <app-footer></app-footer>
  </div>
</template>

<!-- 2行为:逻辑处理 -->
<script>
  // 局部注册组件
  import Users from './components/Users'
  import Header from './components/Header'
  import Footer from './components/Footer'

  export default {
    name: 'App',
    data() {
      return {
        title: "这是一个干净的脚手架项目!"
      }
    },
    components: {
      "users": Users,
      "app-header": Header,
      "app-footer": Footer

    }
  }
</script>

<!-- 3样式:解决样式 -->
<style scoped>
  h1 {
    color: purple;
  }
</style>

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019/01/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • components/Users.vue
  • components/Header.vue
  • components/Footer.vue
  • App.vue
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档