vue2.0学习小列子

参考地址:https://segmentfault.com/a/1190000006165434

例1:

<template>
<div id="app">
  <div class="main" v-cloak @click="hideTooltip">
    <div class="tooltip" v-if="show_tooltip" @click.stop>
      <input type="text" v-model="text_content">
    </div>
    <p @click.stop="toggleTooltip">{{text_content}}</p>
  </div>
</div>
</template>

<script>
/*import tab1 from './components/tabs/tab1.vue'
import tab2 from './components/tabs/tab2.vue'*/
export default {
  name: 'app',
  data(){
    return {
      show_tooltip:false,
      text_content:'Edit me'
    }
  },
  methods: {
    hideTooltip(){
      this.show_tooltip=false;
    },
    toggleTooltip(){
      this.show_tooltip=!this.show_tooltip;
    }
  }
}
</script>

<style>
*{
  padding:0;
  margin:0;
  box-sizing:border-box;
}
[v-cloak]{
  display: none;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* text-align: center;
  color: #2c3e50;
  margin-top: 60px; */
  100%;
}
.main{
  height:300px;
  position:relative;
  padding-top: 150px;
}
.tooltip{
  position:absolute;
  left:50%;
  top:80px;
  290px;
  padding:10px;
  margin-left:-150px;
  border-radius: 3px;
  background-color: #5c9bb7;
}
.tooltip:after{
  content:'';
  position:absolute;
  left:50%;
  0;
  height:0;
  bottom:-6px;
  border-left:6px solid transparent;
  border-right:6px solid transparent;
  border-top:6px solid #5190ac;
}
.tooltip input{
  border: none;
   100%;
  line-height: 34px;
  border-radius: 3px;
  box-shadow: 0 2px 6px #bbb inset;
  text-align: center;
  font-size: 16px;
  font-family: inherit;
  color: #8d9395;
  font-weight: bold;
  outline: none;
}
p{
  font-size:22px;
  font-weight:bold;
  color:#6d8088;
  height: 30px;
  cursor:pointer;
  text-align: center;
}
p:before{
  content:'';
  display:inline-block;
  margin-right:5px;
  font-weight:normal;
  vertical-align: text-bottom;
}
</style>

例2

<template>
<div id="app">
  <div id="main">
    <nav>
      <a v-for="(item,index) in items" :class="{active:item.active}" @click="makeActive(item,index)">{{item.name}}</a>
    </nav>
    <p>You chose<b>{{active}}</b></p>
  </div>
</div>
</template>

<script>
/*import tab1 from './components/tabs/tab1.vue'
import tab2 from './components/tabs/tab2.vue'*/
export default {
  name: 'app',
  data(){
    return {
      active:'HTML',
      items:[
        {name:'HTML',active:true},
        {name:'CSS',active:false},
        {name:'Javascript',active:false},
        {name:'Vue.js',active:false}
      ]
    }
  },
  methods: {
    makeActive(item,index){
      this.active=item.name;
      for(var i=0;i<this.items.length;i++){
        this.items[i].active=false
      }
      this.items[index].active=true
    }
  }
}
</script>

<style>
*{
  padding:0;
  margin:0;
  box-sizing:border-box;
}
[v-cloak]{
  display: none;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* text-align: center;
  color: #2c3e50;
  margin-top: 60px; */
  100%;
}
#main{
  432px;
  margin:0 auto;
  text-align: center;
}
nav{
  display: inline-block;
  margin:60px auto 45px;
  background-color:#5597b4;
  box-shadow:0 1px 1px #ccc;
  border-radius:2px;
}
nav a{
  display: inline-block;
  padding:18px 30px;
  color:#fff !important;
  font-weight: bold;
  font-size:16px;
  text-decoration: none;
  line-height:1;
  background-color: transparent;
  transition: background-color 0.25s;
  cursor:pointer;
}
b{
    display:inline-block;
  padding:5px 10px;
  background-color:#c4d7e0;
  border-radius:2px;
  font-size:18px;
}
.active{
  background:#ccc;
}
</style>

例3:

 1 <template>
 2     <div class="nav">
 3         <ul>
 4             <router-link tag="li" to="/home" active-class="active">
 5                 <a href="javascript:;">首页</a>
 6             </router-link>
 7             <router-link to="/follow" tag="li" active-class="active">
 8             <a href="javascript:;">关注</a>
 9         </router-link>
10         <router-link to="/column" tag="li" active-class="active">
11             <a href="javascript:;">栏目</a>
12         </router-link>
13         </ul>
14     </div>
15 </template>
16 <script>
17 export default{
18 
19 }
20 </script>
21 <style scoped> 
22 .nav{
23     100%;
24     position:fixed;
25     top:0;
26     left:0;
27     z-index:2;
28     background:#fff;
29 }
30 .nav ul{
31     4.38rem;
32     height:0.6rem;
33     margin:0 auto;
34 }
35 .nav li{
36     1.46rem;
37     height:0.6rem;
38     line-height:0.6rem;
39     float:left;
40     text-align: center;
41     box-sizing:border-box;
42 }
43 .nav li a{
44     display:block;
45     1.46rem;
46     height:0.6rem;
47     font-size:0.3rem;
48     color:#9e9a95;
49     text-decoration: none;
50 }
51 .nav li.active a{height:0.6rem; border-bottom:0.1rem solid #5477b2; color:#5477b2;}
52 </style>

日常所遇,随手而记。
原文地址:https://www.cnblogs.com/zhihou/p/7491044.html