美文网首页
2017-3-31 VUE

2017-3-31 VUE

作者: 阿苏菇凉 | 来源:发表于2017-03-31 18:48 被阅读0次
<div id="app">
        <fieldset>
            <legend>this is a demo</legend>
            <div class="">
                <label>姓名:</label>
                <input type="text" name="" v-model="NewPerson.name">
            </div>
            <div class="">
                <label>年龄:</label>
                <input type="text" name="" v-model="NewPerson.age">
            </div>
            <div class="">
                <label>性别:</label>
                <select v-model="NewPerson.sex">
                    <option value="male">男</option>
                    <option value="female">女</option>
                </select>
            </div>
            <div>
                <button @click="createPerson">创建</button>
            </div>
        </fieldset>
        <table>
            <tr>
                <td>姓名</td>
                <td>年龄</td>
                <td>性别</td>
                <td>删除</td>
            </tr>
            <tr v-for="(person, key) of people">
                <td>{{ person.name }}</td>
                <td>{{ person.age }}</td>
                <td>{{ person.sex }}</td>
                <td :class="'text-center'"><button @click="deletePerson(key)">删除</button></td>
            </tr>
        </table>
    </div>
    <script>
        var vm = new Vue ({
            el: '#app',
            data: {
                NewPerson: {
                    name: '',
                    age: 0,
                    sex: 'male'
                },
                people: [
                    {
                        name: 'A',
                        age: 10,
                        sex: 'male'
                    },
                    {
                        name: 'B',
                        age: 13,
                        sex: 'female'
                    },
                    {
                        name: 'C',
                        age: 15,
                        sex: 'female'
                    }
                ]
            },
                methods:{
                    createPerson: function(){
                        this.people.push(this.NewPerson);
                        this.NewPerson = {name: '', age: 0, sex: 'male'}
                    },
                    deletePerson: function(index){
                        console.log(index)
                        this.people.splice(index,1);
                    }
                }
    })
    </script>
<div id="main" @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>
<script type="text/javascript">
    var demo = new Vue({
  el: '#main',
  data: {
    show_tooltip: false, 
    text_content: 'Edit me.'
  },
  methods: {
    hideTooltip: function() {
      this.show_tooltip = false; 
    },
    toggleTooltip: function() {
      this.show_tooltip = !this.show_tooltip;
    }
  }
});
</script>
<div id="main">
    <nav @click.prevent>
        <a v-for="item in items" :class="{'show': item.active}" @click="makeActive(item, $index)">{{item.name}}</a>
    </nav>
    <p>You chose <b>{{active}}</b></p>
</div>
<script type="text/javascript">
    var vm = new Vue({
    el:'#main',
    data:{
        active:'HTML', 
        items:[ 
            {name:'HTML', active:true}, 
            {name:'CSS', active:false},
            {name:'JavaScript', active:false},
            {name:'Vue.js', active:false}
        ]
    },
    methods: {
        makeActive: function(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>

相关文章

  • 2017-3-31 VUE

  • 053 Release date: 2017-3-31 Type:Comedy/Family Running ti...

  • 2017-3-31

    开始运动,用keep APP开始做有氧运动,每天30分钟以上。 早餐:少吃主食,其余随便吃 午餐:酸奶,黄瓜,水煮...

  • 2017-3-31

    今天折腾了张经理一天,见了两个客户,第一个是已经成交了的那个,再一次体会到张经理的厉害,对于公司运营各个板块各个方...

  • 2017-3-31

    一、学习任务 英语:记背单词 新76 旧100 何凯文每日一句更新 长难句半小节 数学:第四章第四小节~有理函数...

  • 2017-3-31

    早餐:粥+鸡蛋 午餐:藕片+西红柿炒鸡蛋+米饭 运动休息日

  • 2017-3-31倾听

    2017-3-31倾听 作者:观澜 在我们的生活的方方面面都要与人进行各种各样的交流。我们通过说话发出我们的信息,...

  • 二三四五 002195

    ts:2017-3-31 综合分析 估值分析 财务分析 经营分析 2016-12-31 一、概述。公司致力于成为“...

  • 海信电器 600060

    ts:2017-3-31 综合分析 估值分析 财务分析 经营分析 2016-12-31 一、经营情况讨论与分析(一...

  • 健康日志365.15——健康长城③

    健康日志365.15 时间:2017-3-31 主题:修筑一座健康长城③ 健康长城③ 健康长城 一笔巨额财富的秘密...

网友评论

      本文标题:2017-3-31 VUE

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