zoukankan      html  css  js  c++  java
  • vue学习日记一

    添加列表及删除列表:

     效果图:

     

     html及js代码:

    <div id="app">
        <p>姓名:<input type="text" v-model="name" placeholder="请输入姓名"></p>
        <p>年龄:<input type="text" v-model='age' placeholder="请输入年龄"></p>
        <p><input type="button" value="添加" @click="addList"></p>
        <table>
            <thead>
                <tr>
                    <th><input type="checkbox" v-model="checked" @click="checkedAll"></th>
                    <th>编号</th>
                    <th>姓名</th>
                    <th>年龄</th>
                </tr>
            </thead>
            <tbody>
                <template v-if="items.length!=0">
                    <tr v-for="(item,index) in items">
                        <td><input type="checkbox" v-model="checkedIds" :value="index"></td>
                        <td>{{index+1}}</td>
                        <td>{{item.name}}</td>
                        <td>{{item.age}}</td>
                    </tr>
                </template>
                <template v-else>
                    <tr>
                        <td colspan="4">暂无数据!</td>
                    </tr>
                </template>
            </tbody>
        </table>
        <p><input type="button" value="删除" @click="deleteList"></p>
        <p>{{tip}}</p>
    </div>
    var vue = new Vue({
            el:'#app',
            data:{
                checked:false,
                name:'',
                age:'',
                items:[],
                checkedIds:[],
                tip:''
            },
            methods:{
                addList:function(){
                    this.items.push({name:this.name,age:this.age});
                    this.reset();
                },
                checkedAll:function(){
                    this.checked = !this.checked;
                    if(this.checked){
                        for(var i = 0; i < this.items.length; i++){
                            this.checkedIds.push(i);
                        }
                    }else{
                        this.checkedIds = [];
                    }
                },
                deleteList:function(){
                    var ids = this.checkedIds;
                    if(ids.length == 0){
                        this.tip = '请至少选择一项!'
                    }else{
                        for(var i = ids.length-1; i >= 0; i--){
                            this.items.splice(ids[i],1)
                        }
                        this.tip = '删除成功!'
                        this.reset();
                    }
                },
                reset:function(){
                    this.name = '';
                    this.age = '';
                    this.checkedIds = [];
                    this.checked = false;
                }
            }
        });

    vue-resource跨域请求——百度搜索提示:

     效果图:

     

     html及js代码: 

    <div id="app">
        <input type="text" placeholder="请输入搜索内容" v-model="value" @keyup="getSearchResult">
        <ul v-if="items.length!=0">
            <li v-for="item in items">{{item}}</li>
        </ul>
        <ul v-else>
            <li>暂无数据</li>
        </ul>
    </div> 
    var vue = new Vue({
            el:'#app',
            data:{
                value:'',
                items:[]
            },
            methods:{
                getSearchResult:function(){
                    var that = this;
                    this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?',{
                        params:{
                            wd:this.value
                        },
                        jsonp:'cb'
                    }).then(function(res){
                        that.items = JSON.parse(res.bodyText).s;
                    },function(error){
    
                    })
                }
            }
        });
  • 相关阅读:
    png图片透明在ie6中显示问题
    DIV背景图片在Firefox下不显示,IE下正常
    整理:兼容 IE、Firefox、Opera和Safari
    IE6背景消失问题
    鼠标悬停换图片或背景
    网站团队组建方案
    CSS兼容IE6,IE7,FF的技巧
    打造MySQL版的最新IP数据库
    域名判断后跳转——PHP跳转代码_ASP跳转代码_JS跳转代码
    IE6文字消失、背景圖消失之謎
  • 原文地址:https://www.cnblogs.com/kerry-xu/p/8144046.html
Copyright © 2011-2022 走看看