vue快速入门 笔记 +axios

1. 笔记

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue学习</title>
    <!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<style>
    .active{
        border: 1px solid red;
    }
    .tq{
        width: 20%;
        background:#eee;
        margin-right: 5px;
    }
</style>
</head>
<body>
    <div id="app">
        <h2>天知道</h2>
        <input type="text" v-model="city" @keyup.enter="getweather">
        <input type="button" value="搜索" @click="getweather1">
        <div style="display: flex;justify-content: space-around;">
            <div class="tq" v-for="(item,k) in weatherdata">
                <span>{{item['date']}}</span>
                <span>{{item.wea}}</span>
                <span>{{item.win}}</span>
                <span>{{item.win_speed}}</span>
            </div>
        </div>
        <h2>axios</h2>
        <input type="button" class="get" value="getaxios">
        <input type="button" class="post" value="postaxios">
        <h2>记事本</h2>
        <input type="text" v-model="jishiben" @keyup.enter="addj">
        <ul>
            <li v-for="(jvalue,jkey) in jdata">
                {{jkey+1}}记事本{{jvalue}}
                <button @click="removejishiben(jkey)">删除</button>
            </li>
        </ul>
        <h3 v-if="jdata.length != 0">数据条数{{jdata.length}}</h3>
        <div v-show="jdata.length != 0" @click="clearj">清空</div>
        <h2>v-model</h2>
        <input type="button" value="修改message" @click="setm">
        <input type="text" v-model="message">
        {{message}}
        <h2>v-for</h2>
        <input type="button" value="添加数据" @click="adddata">
        <input type="button" value="移除数据" @click="removedata">
        <ul>
            <li v-for="(it,index) in arr">
                {{index}}for循环{{it}}
            </li>
        </ul>
        <h3 v-for="item in vetables" v-bind:title="item.name">
            {{item.name}}
        </h3>
        <h2>v-bind 操作class src  title</h2>
        <img v-bind:src="imagesrc" alt=""></br>
        <img :src="imagesrc" alt="" :title="imagetitle+'!!!'" :class="isactive?'active':''" @click="toggleActive"></br>
        <img :src="imagesrc" alt="" :title="imagetitle+'!!!'" :class="{active:isactive}" @click="toggleActive"></br>
        <h2>v-if操作dom  频繁切换用show</h2>
        <input type="button" value="切换if显示" @click="changif">
        <img src="./tbs.jpg" v-show="ifshow" alt="">
        <h2>v-show</h2>
        <input type="button" value="切换显示状态" @click="changeshow">
        <input type="button" value="累加" @click="addage">
        <img src="./tbs.jpg" v-show="isshow" alt="">
        <img src="./tbs.jpg" v-show="age>=18" alt="">
        <h2>计数器</h2>
        <div>
            <button @click="sub">-</button>
            <span>{{num}}</span>
            <button @click="add">+</button>
        </div>
        <h2>v-on</h2>
        <input type="button" value="v-on指令" v-on:click="doit">
        <input type="button" value="v-on简写" @click="doit">
        <input type="button" value="v-on双击" @dblclick="doit">
        <div @click="changefood">{{food}}</div>
        <input type="text" @keyup.enter="sayui">
        <h2>v-html</h2>
        <div v-html="content"></div>
        <div v-text="content"></div>
        <h2>v-text</h2>
        <div v-text="message + '!'"></div>
        <div v-text="info"></div>
        <div>{{info + '!'}}</div>
        <h2>4个小时带你快速入门vue之第6课之前</h2>
        {{ message }}    </br>
        {{ duixiang.name }}</br>
        {{ duixiang }}    </br>
        {{ shuzu }}    </br>
        {{ shuzu[2] }}    </br>
      </div>
      <script>
          var app = new Vue({
                el: '#app',
                data: {
                    message: 'Hello1 祥云小镇!',
                    info: '详细信息',
                    content: "<a href='http://baidu.com'>百度一下</a>",
                    duixiang: {
                        "name":"任达华",
                        "age":99,
                    },
                    shuzu:["范冰冰","李冰冰","赵冰冰"],
                    food :"油麦菜",
                    num :0,
                    isshow :true,
                    age :9,
                    ifshow :true,
                    imagesrc :'./tbs.jpg',
                    isactive :false,
                    imagetitle :'土拨鼠',
                    arr:["东城区","北城区","西城区","南城区"],
                    vetables:[
                        {"name":"番茄炒蛋"},
                        {"name":"番茄d炒蛋"},
                    ],
                    jdata:["记事本1","记事本2","记事本3"],
                    jishiben :"来啊,快活呀",
                    weatherdata:[],
                    city:"北京",

                },
                methods:{
                    doit:function(){
                        alert("做v-on")
                    },
                    changefood:function(){
                        this.food += "真好吃"
                    },
                    sub:function(){
                        if(this.num>0){
                            this.num--
                        }else{
                            alert("近距离圣诞节")
                        }
                    },
                    add : function(){
                        if (this.num>=10){
                            alert("憋着")
                        }else{
                            this.num++
                        }
                    },
                    changeshow : function(){
                        this.isshow = !this.isshow
                    },
                    addage : function(){
                        this.age++
                    },
                    changif : function(){
                        this.ifshow = !this.ifshow
                    },
                    toggleActive:function(){
                        this.isactive = !this.isactive
                    },
                    adddata : function(){
                        this.vetables.push({"name":"了解了解"})
                    },
                    removedata :function(){
                        this.vetables.shift()
                    },
                    sayui :function(){
                        alert("大V深V")
                    },
                    setm : function(){
                        this.message="哒哒哒哒哒"
                    },
                    addj:function(){
                        this.jdata.push(this.jishiben)
                    },
                    removejishiben:function(index){
                        this.jdata.splice(index,1)
                    },
                    clearj:function(){
                        this.jdata=[]
                    },
                    getweather:function(){
                        var that =this;
                        axios.get('https://www.tianqiapi.com/free/week?appid=25555884&appsecret=B8lHZDxq', {
                            params: {
                            city: that.city
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                        })
                        .then(function (r) {
                            // always executed
                            that.weatherdata = r.data.data
                            console.log(r.data.data);
                        }); 
                    },
                    getweather1:function(){
                        var that =this;
                        axios.get('https://www.tianqiapi.com/free/week?appid=25555884&appsecret=B8lHZDxq', {
                            params: {
                            city: that.city
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                        })
                        .then(function (r) {
                            // always executed
                            that.weatherdata = r.data.data
                            console.log(r.data.data);
                        }); 
                    },

                }
            })
      </script>
      <script>
        document.querySelector('.get').onclick=function(){
            axios.get('https://www.tianqiapi.com/free/week?appid=25555884&appsecret=B8lHZDxq', {
                    params: {
                    ID: 12345
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function (r) {
                    // always executed
                    console.log(r)
                });  
        }
        document.querySelector('.post').onclick=function(){
            axios.post('/user', {
                firstName: 'Fred',
                lastName: 'Flintstone'
            })
            .then(function (response) {
                console.log(response);
            })
            .catch(function (error) {
                console.log(error);
            });
        }
      </script>
</body>
</html>

2.手把手教你用vue-cli搭建vue项目

这样vue项目部署在服务器只需要

npm run build

 域名配置到dist下就可以了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值