主頁 > 前端設計 > Vue整理

Vue整理

2020-12-14 06:47:30 前端設計

一、Vue

Vue是遵循MVVW架構模式實作的前端框架

npm匯入路徑:https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js

MVVM架構 Model資料 View模板 ViewModel處理資料

1、ES6的常用語法:

變數的定義,var,let,const

  1. Var 變數的提升,函式作用域 全域作用域,重新定義不會報錯,可以重新賦值
  2. let 塊級作用域 { },重新定意會報錯,可以重新賦值
  3. const 定義不可修改的常量,不可以重新賦值

箭頭函式的this取決于當前的背景關系環境:類似于python的匿名函式

this指當前函式最近的呼叫者,距離最近的呼叫者

解構:
字典解構 {key,key,...} 注:要使用key才行
陣列結構 [x,y,.....]

    let obj = {
        a:1,
        b:2
    };
    let hobby = ["吹牛", "特斯拉", "三里屯"];
    let {a,b} = obj;
    let [hobby1,hobby2,hobby3] = hobby;
    console.log(a);
    console.log(b);
    console.log(hobby1);
    console.log(hobby2);
    console.log(hobby3);

2、Vue的核心思想是資料驅動視圖

1)Vue的常用指令

v-text:獲取文本內容

v-html:獲取html內容

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <h2 v-text="name"></h2>
    <h3 v-text="age"></h3>
    <div v-html="hobby"></div>
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        name:"PDD",
        age:18,
        hobby:"<ul><li>學習</li><li>刷劇</li><li>Coding</li></ul>"
    }
});
</script>
</body>
</html>

v-for:回圈獲取陣列

v-for:回圈獲取字典

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <ul>
        <li v-for="(course,index) in course_list" :key="index">{{index}}:{{course}}</li>
        <li v-for="(item,index) in one" :key="index">
            {{index}}:{{item.name}}:{{item.age}}:{{item.hobby}}
        </li>
    </ul>
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        course_list:["classname","teacher","student"],
        one:[{name:"eric",age:"18",hobby:"music"},
            {name:"bob",age:"18",hobby:"dance"}]
    }
})
</script>
</body>
</html>

v-bind:自定制顯示樣式,動態系結屬性,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_app{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <div v-bind:>
    </div>
    <img :src="https://www.cnblogs.com/wylshkjj/p/my_src" alt=""> <!--  v-bind: 可以簡寫為 : -->
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        is_show:true, //true表示顯示style樣式,false不顯示style樣式
        my_src:"http://i0.hdslb.com/bfs/archive/590f87e08f863204820c96a7fe197653e2d8f6e1.jpg@1100w_484h_1c_100q.jpg"
    }
})
</script>
</body>
</html>

v-on@事件名:事件系結

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <!-- v-on@click只會執行一次,是在第一次進入頁面的時候,@click會回圈執行 -->

    <button @click="my_click('hello')" v-on="{mouseenter:my_enter,mouseleave:my_leave}">
        點擊彈窗
    </button>
<!--    <button @click="my_click('hello')" @mouseenter="my_enter",@mouseleave="my_leave">  繁瑣寫法-->
<!--        點擊彈窗     -->
<!--    </button>    -->
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{},
    methods:{
        my_click:function(x){
            alert("luke" + x)
        },
        my_enter:function(){
            console.log("滑鼠移入事件")
        },
        my_leave:function(){
            console.log("滑鼠移出事件")
        }
    }
})
</script>
</body>
</html>

v-if:條件判斷
v-if v-else-if v-else

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <div v-if="role == 'admin' ">管理員你好</div>
    <div v-else-if="role == 'hr' ">查看簡歷</div>
    <div v-else>沒有權限</div>

</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        role:"admin"
    },
    methods:{}
})
</script>
</body>
</html>

v-show:布林值型別判斷

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <div v-show="admin">管理員你好</div>
    <div v-show="hr">查看簡歷</div>
    <div v-show="others">沒有權限</div>
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        admin:true,
        hr:false,
        others:false,
    },
    methods:{}
})
</script>
</body>
</html>

綜合案例

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <div v-show="admin">管理員你好</div>
    <div v-show="hr">查看簡歷</div>
    <div v-show="others">沒有權限</div>
    <button @click="my_click">點擊顯示或隱藏</button>
    <div v-show="is_show">hello</div>
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        admin:true,
        hr:false,
        others:false,
        is_show:false
    },
    methods:{
        my_click:function(){
            this.is_show=!this.is_show
        }
    }
})
</script>
</body>
</html>

v-model:獲取資料,標簽的屬性設定 ,獲取其屬性值,用戶資訊等,例如input,select等

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="username">
    {{username}}
    <hr>
    <textarea type="text" cols="30" rows="10" v-model="article">
        {{article}}
    </textarea>
    <hr>
    <select name="" v-model="choices">
        <option value="https://www.cnblogs.com/wylshkjj/p/1">阿薩德</option>
        <option value="https://www.cnblogs.com/wylshkjj/p/2">主執行緒</option>
        <option value="https://www.cnblogs.com/wylshkjj/p/3">權威</option>
    </select>
    {{choices}}
    <hr>
    <select name="" v-model="choices_multiple" multiple>
        <option value="https://www.cnblogs.com/wylshkjj/p/1">阿薩德</option>
        <option value="https://www.cnblogs.com/wylshkjj/p/2">主執行緒</option>
        <option value="https://www.cnblogs.com/wylshkjj/p/3">權威</option>
    </select>
    {{choices_multiple}}
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        username:"1234",
        article:"123456",
        choices:"",
        choices_multiple:['1']
    },
    methods:{}
})
</script>
</body>
</html>

v-model.lazy:失去游標系結資料事件
v-model.lazy.number:資料型別的轉換
v-model.lazy.trim:清除空格

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model.lazy="username">
        {{username}}
    <hr>
    <!--  前端默認只顯示一個空格,pre使資料原始化展示  -->
    <input type="text" v-model.lazy="username">
        <pre>{{username}}</pre>
    <hr>
    <!--    -->
    <input type="text" v-model.lazy.trim="username_trim">
        <pre>{{username_trim}}</pre>
    <hr>
    <input type="text" v-model.lazy.number="article">
    {{article}}
    {{typeof article}}
</div>
<script>
const app = new Vue({
    el:"#app",
    data:{
        username:"1234",
        username_trim:"1234",
        article:"123456"
    },
    methods:{}
})
</script>
</body>
</html>

2)自定義指令

v-自定義的函式(指令):自定制函式(指令)
Vue.directive()

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <div  v-pin.right.top="pinned"></div>
</div>
<script>
    Vue.directive("pin",function(el,binding){
        console.log(el); //指令的標簽元素
        console.log(binding); //指令的所有資訊
        let adr = binding.modifiers;
        if(binding.value){
            //定位到瀏覽器的右下角
            el.style.position = "fixed";
            // el.style.right='0';
            // el.style.bottom='0';
            //指令修飾符定位
            for (let posi in adr){
                el.style[posi]=0;
            }
        }else{
            el.style.position = "static";
        }
    });
    const app = new Vue({
        el:"#app",
        data:{
            pinned:true
        }
    })
</script>
</body>
</html>

3)方法集合

v-text
v-html
v-for
v-if v-else-if v-else
v-bind 系結屬性
v-on 系結事件
v-show display
v-model 資料雙向系結
input
textarea
select
指令修飾符
.lazy
.number
.trim
自定義指令
Vue.directive('指令名',function(el,引數binding){ })
el 系結指令的標簽元素
binding 指令的所有資訊組成的物件
value 指令系結資料的值
modifiers 指令修飾符組成的物件

二、Vue獲取DOM,資料監聽,組件,混合和插槽

注:“:” 是指令 “v-bind”的縮寫,“@”是指令“v-on”的縮寫;“.”是修飾符,

1、Vue獲取DOM

給標簽加ref屬性:ref="my_box"
獲取:this.$refs.my_box;

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <div ref="my_box"></div>
    <button v-on:click="my_click">點擊顯示文本</button>
</div>
<script>
    const app = new Vue({
        el:"#app",
        data:{},
        methods:{
            my_click: function(){
                let ele = this.$refs.my_box;
                console.log(ele);
                ele.innerText = "hello"
            }
        }
    })
</script>
</body>
</html>

computed:計算屬性,放的是需要處理的資料

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <table>
        <tr>
            <th>科目</th>
            <th>成績</th>
        </tr>
        <tr>
            <td>Python</td>
            <td><input type="text" v-model.number="python"></td>
        </tr>
        <tr>
            <td>Java</td>
            <td><input type="text" v-model.number="java"></td>
        </tr>
        <tr>
            <td>Go</td>
            <td><input type="text" v-model.number="go"></td>
        </tr>
        <tr>
            <td>總分</td>
            <td>{{total}}</td>
        </tr>
        <tr>
            <td>平均分</td>
            <td>{{average}}</td>
        </tr>
<!-- 繁瑣方法 -->
<!-- <tr> -->
<!-- <td>總分</td> -->
<!-- <td>{{python + java + go}}</td> -->
<!-- </tr>  -->
<!-- <tr> -->
<!-- <td>平均分</td> -->
<!-- <td>{{total/3}}</td> -->
<!-- </tr> -->

    </table>
</div>
<script>
    const app = new Vue({
        el:"#app",
        data:{
            python:"",
            java:"",
            go:""
        },
        methods:{},
        computed:{
            total: function(){
                return this.python + this.java + this.go
            },
            average: function(){
                return this.total/3
            }
        }
    })
</script>
</body>
</html>

2、資料監聽

watch :監聽不到可以添加deep屬性
deep:true :深度監聽,deep監聽不到,可以使用 $.set() 屬性操作值
$.set()

字串監聽:監聽到的新舊值不同,
陣列:只能監聽到長度的變化,新舊值相同,改變陣列值的時候要使用 $set(array,index,value)
物件:只能監聽到value的改變,必須深度監聽:deep,增加物件的key必須使用:$set(array,key,value)

注:陣列監聽有坑

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    {{name}}
    <br>
    {{hobby}}
    <br>
    {{obj}}
    <br>
    <button v-on:click="my_click">點我改變資料</button>
</div>
<script>
    const app = new Vue({
        el:"#app",
        data:{
            name:"eric",
            hobby:["打游戲","打豆豆"],
            obj:{
                boy:"PDD",
                age:23
            }
        },
        methods:{
            my_click: function(){
                // 修改name資料
                this.name = "bob";
                // this.hobby.push("潛水");
                // this.hobby[0] = "潛水";
                // app.$set(this.hobby,0,"潛水");
                // this.obj.age = 20;
                // this.obj["sex"] = "男";
                app.$set(this.obj,"sex","男");
            }
        },
        watch: {
            name: {
                handler: function(val,oldVal){
                    console.log(val);
                    console.log(oldVal);
                }
            },
            hobby: {
                handler: function(val,oldVal){
                    // 改變陣列的長度的時候新舊值相同
                    console.log(val);
                    console.log(oldVal);
                },
                // deep: true
            },
            obj: {
                handler: function(val,oldVal){
                    console.log(val);
                    console.log(oldVal);
                },
                deep: true
            }
        }
    })
</script>
</body>
</html>

3、組件

可復用
全域組件的定義:Vue.component("myheader",{})
全域組件的使用:<myheader></myheader>

<!-- 全域注冊組件 -->
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <myheader></myheader>
</div>
<div id="apps">
    <myheader></myheader>
</div>
<script>
    Vue.component("myheader",{
        template: '<div><h1>{{ title }}</h1></div>',
        // template: '<div><h1>Hello world!</h1></div>',
        data(){  // 物件的單體模式
            return{
                title: "HelloWorld!"
            }
        },
        methods:{}
    });
    const app = new Vue({
        el:"#app",
        data:{},
        methods:{}
    });
    const apps = new Vue({
        el:"#apps",
        data:{},
        methods:{}
    })
</script>
</body>
</html>

區域組件的定義:components: {my_com: my_com_config}
區域組件的使用:<my_com></my_com>

<!-- 區域注冊組件 -->
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <my_com></my_com>
</div>
<script>
    let my_com_config = {
        template: '<div><h1>區域組件</h1></div>'
    };
    const app = new Vue({
        el:"#app",
        components: {
            my_com: my_com_config
        }
    })
</script>
</body>
</html>

父子組件:
注:組件只識別一個作用域塊

<!-- 父子組件的進本使用 -->
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <my_com></my_com>
</div>
<script>
    let child_config = {
        template: '<div><h2>子組件</h2></div>'
    };
    let my_com_config = {
        template: '<div><h1>父組件</h1><child></child></div>',
        components: {
            child: child_config
        }
    };
    const app = new Vue({
        el:"#app",
        components: {
            my_com: my_com_config
        }
    })
</script>
</body>
</html>

父子組件的通信:
父子通信(主操作在父級):
父級定義方法::father_say="f_say"
子級呼叫方法:props: ['father_say']
子級使用方法(模板語言直接呼叫):{{father_say}}

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <my_com></my_com>
</div>
<script>
    let child_config = {
        template: '<div><h2>子組件</h2><p>father_say:{{father_say}}</p></div>',
        props: ['father_say']
    };
    let my_com_config = {
        template: '<div><h1>父組件</h1><child :father_say="f_say"></child></div>',
        components: {
            child: child_config
        },
        data(){
            return {
                f_say: "滾~~"
            }
        }
    };
    const app = new Vue({
        el:"#app",
        components: {
            my_com: my_com_config
        }
    })
</script>
</body>
</html>

子父通信(主操作在子級):
子集定義方法:@click='my_click'
子級提交事件:this.$emit("事件名",data)
父級系結子級提交的事件:@事件名="處理的方法"
父級處理方法: methods: {處理的方法: function(data){data 資料處理} }
父級使用方法(模板語言直接呼叫):{{say}}

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <my_com></my_com>
</div>
<script>
    let child_config = {
        template: "" +
            "<div>" +
            "<h2>子組件</h2>" +
            "<button @click='my_click'>向父級傳送資料</button>" +
            "</div>",
        methods: {
            my_click(){
                // 子組件提交事件名稱
                this.$emit("son_say","滾~~")
            }
        }
    };
    let my_com_config = {
        template: '' +
            '<div>' +
            '<h1>父組件</h1>' +
            '<child @son_say="my_son_say"></child>' +
            '<p>son_say:{{say}}</p>' +
            '</div>',
        components: {
            child: child_config
        },
        data(){
            return {
                say:""
            }
        },
        methods: {
            my_son_say: function(data){
                this.say = data
            }
        }
    };
    const app = new Vue({
        el:"#app",
        components: {
            my_com: my_com_config
        }
    })
</script>
</body>
</html>

非父子級通信:
定義中間調度器:let event = new Vue()
需要通信的組件向中間調度器提交事件:event.$emit("事件名", data)
接收通信的組件監聽中間調度器里的事件:event.$on("事件名", function(data){data操作(注意:this的問題)})

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
<eric></eric>
<jing></jing>
</div>
<script>
    let midlen = new Vue();
    let eric = {
        template: "" +
            "<div>" +
            "<h1>This is Eric</h1>" +
            "<button @click='my_click'>點擊通知靜靜</button>" +
            "</div>",
        methods: {
            my_click(){
                // 通知bob,晚上等我
                // 向bob,提交事件
                midlen.$emit("email","晚上,一起吃飯")
            }
        }
    };
    let jing = {
        template: "" +
            "<div>" +
            "<h1>This is jing</h1>" +
            "<p>eric和我說:{{ eric_email }}</p>" +
            "</div>",
        data(){
            return {
                eric_email: ""
            }
        },
        mounted(){
            // 組件加載完成后執行的方法
            let that = this;
            midlen.$on("email", function(data){
                that.eric_email = data;
                // console.log(data);
            })
        }
    };
    const app = new Vue({
        el:"#app",
        components: {
            eric: eric,
            jing: jing
        }
    })
</script>
</body>
</html>

4、混合

實際上在框架中用的很少
作用:復用共用的代碼塊
minxins:[base]

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <button @click=\"show_text\">點擊顯示文本</button>
    <button @click=\"hide_text\">點擊隱藏文本</button>
    <button @mouseenter="show_text" @mouseleave="hide_text">提示框</button>
    <div v-show=\"is_show\"><h1>look wyl and kjj</h1></div>
</div>
<script>
    const app = new Vue({
        el: "#app",
        data: {
            is_show:false
        },
        methods: {
            show_text: function(){
                this.is_show = true
            },
            hide_text: function(){
                this.is_show = false
            }
        }
    })
</script>
</body>
</html>
<!-- 混合示例 -->
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <com1></com1>
    <com2></com2>
</div>
<script>
    let base = {
        data(){
            return {
                is_show:false
            };
        },
        methods: {
            show_text(){
                this.is_show = true
            },
            hide_text(){
                this.is_show = false
            }
        }
    };
    let com1 = {
        template:"" +
            "<div>" +
            "<button @click=\"show_text\">點擊顯示文本</button>" +
            "<button @click=\"hide_text\">點擊隱藏文本</button>" +
            "<div v-show=\"is_show\"><h1>look wyl and kjj</h1></div>" +
            "</div>",
        mixins: [base],
        data(){
            return {
                is_show: true
            }
        }
    };
    let com2 = {
        template:"" +
            "<div>" +
            "<button @mouseenter=\"show_text\" @mouseleave=\"hide_text\">提示框</button>" +
            "<div v-show=\"is_show\"><h1>look wyl and kjj</h1></div>" +
            "</div>",
        mixins: [base],
    };
    const app = new Vue({
        el:"#app",
        components: {
            com1: com1,
            com2: com2
        }
    })
</script>
</body>
</html>

5、插槽

作用:實作組件內容的分發
slot:
直接使用slot標簽:<slot></slot>
名命slot標簽:
先給slot加name屬性:<slot name="title"></slot>
給標簽元素添加slot屬性:<h3 slot="title">Python</h3>

<!-- 未命名的slot標簽 -->
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <com>
        <slot>This is jing</slot>
    </com>
    <com>
        <slot>This is wyl</slot>
    </com>
</div>
<template id="my_com">
    <div>
        <h1>這是一個組件</h1>
        <slot></slot>
    </div>
</template>
<script>
    let com = {
        template: "#my_com"
    };
    const app = new Vue({
        el:"#app",
        components: {
            com: com
        }
    })
</script>
</body>
</html>
<!-- 命名的slot標簽 -->
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        .my_box{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div id="app">
    <com>
        <h3 slot="title">Python</h3>
        <p slot="brief">This is jing</p>
    </com>
    <com>
        <h3 slot="title">Git</h3>
        <p slot="brief">This is wyl</p>
    </com>
</div>
<template id="my_com">
    <div>
        <h1>這是一個組件</h1>
        <slot name="title"></slot>
        <slot name="brief"></slot>
    </div>
</template>
<script>
    let com = {
        template: "#my_com"
    };
    const app = new Vue({
        el:"#app",
        components: {
            com: com
        }
    })
</script>
</body>
</html>

三、VueRouter

特點:通過路由和組件實作一個單頁面的應用,

1、路由的注冊:靜態路由

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    <router-link to="/">首頁</router-link>
    <router-link to="/course">課程</router-link>
    <router-view></router-view>
</div>
<script>
    // 定義路由匹配規則
    let url = [
        {
            path:"/",
            component:{
                template:'<div><h1>首頁組件</h1></div>'
            }
        },
        {
            path:"/course",
            component:{
                template:'<div><h1>課程組件</h1></div>'
            }
        }
    ];
    // 實體化VueRouter物件
    let router = new VueRouter({
        routes:url
    });
    // 把VueRouter的實體化物件注冊到Vue的跟實體
    const app = new Vue({
        el:"#app",
        router:router
    })
</script>
</body>
</html>

2、路由的注冊:動態路由(路由的引數)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    <!-- 路由動態系結:to -->
    <router-link :to="{name:'home'}">首頁</router-link>
    <router-link :to="{name:'course'}">課程</router-link>
    <!--  帶有引數的靜態路由系結  -->
    <router-link to="/user/nepenthe?age=20">用戶1</router-link>
    <!--  帶有引數的動態路由系結  -->
    <router-link :to="{name:'user',params:{name:'forget-me-not'},query:{age:'23'}}">用戶2</router-link>
    <router-view></router-view>
</div>
<script>
    // 定義路由匹配規則
    let url = [
        {
            path:"/",
            name:"home",
            component:{
                template:'<div><h1>首頁組件</h1></div>'
            }
        },
        {
            path:"/course",
            name: "course",
            component:{
                template:'<div><h1>課程組件</h1></div>'
            }
        },
        {
            path:"/user/:name",
            // 引數設定(?P<name>.*)
            name: "user",
            component:{
                template:'' +
                    '<div>' +
                        // 獲取路由name:this.$route.name
                        '<h1>{{this.$route.name}}用戶組件</h1>' +
                        // 獲取路由中引數:this.$route.params.name
                        '<h1>username:{{this.$route.params.name}}</h1>' +
                        // 獲取路由中引數(使用?的引數):this.$route.query.age
                        '<h1>age:{{this.$route.query.age}}</h1>' +
                    '</div>',
                // Vue屬性加載完成后執行的方法
                mounted(){
                    console.log(this.$route)
                }
            }
        }
    ];
    // 實體化VueRouter物件
    let router = new VueRouter({
        routes:url
    });
    // 把VueRouter的實體化物件注冊到Vue的跟實體
    const app = new Vue({
        el:"#app",
        router:router
    })
</script>
</body>
</html>

3、路由的注冊:自定義路由

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    <!-- 路由系結:to -->
    <router-link to="/">首頁</router-link>
    <router-link to="/course">課程</router-link>
    <router-link to="/login">登錄</router-link>
    <router-view></router-view>
</div>
<script>
    // 定義路由匹配規則
    let url = [
        {
            path:"/",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>首頁組件</h1>' +
                        '<button @click="my_click">點擊跳轉登錄頁面</button>' +
                    '</div>',
                methods:{
                    my_click: function(){
                        
                        console.log(this.$route);
                        // $route 當前路由的所有資訊
                        console.log(this.$router);
                        // $router VueRouter的實體化物件
                        console.log(this.$el);
                        console.log(this.$data);
                        this.$router.push("/login")
                        // 跳轉頁面 --> 跳轉到登錄組件
                    }
                }
            }
        },
        {
            path:"/course",
            component:{
                template:'<div><h1>課程組件</h1></div>'
            }
        },
        {
            path:"/login",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>登錄組件</h1>' +
                    '</div>'
            }
        }
    ];
    // 實體化VueRouter物件
    let router = new VueRouter({
        routes:url
    });
    // 把VueRouter的實體化物件注冊到Vue的跟實體
    const app = new Vue({
        el:"#app",
        router:router
    })
</script>
</body>
</html>

4、路由的鉤子函式:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    <!-- 路由系結:to -->
    <router-link to="/">首頁</router-link>
    <router-link to="/course">課程</router-link>
    <router-link to="/user">用戶</router-link>
    <router-link to="/login">登錄</router-link>
    <router-view></router-view>
</div>
<script>
    // 定義路由匹配規則
    let url = [
        {
            path:"/",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>首頁組件</h1>' +
                        '<button @click="my_click">點擊跳轉登錄頁面</button>' +
                    '</div>',
                methods:{
                    my_click: function(){

                        console.log(this.$route);
                        // $route 當前路由的所有資訊
                        console.log(this.$router);
                        // $router VueRouter的實體化物件
                        console.log(this.$el);
                        console.log(this.$data);
                        // 跳轉頁面 --> 跳轉到登錄組件
                        this.$router.push("/login")
                    }
                }
            }
        },
        {
            path:"/course",
            component:{
                template:'<div><h1>課程組件</h1></div>'
            }
        },
        {
            path:"/login",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>登錄組件</h1>' +
                    '</div>'
            }
        },
        {
            path:"/user",
            meta:{
                required_login: true
            },
            component:{
                template:'' +
                    '<div>' +
                        '<h1>用戶組件</h1>' +
                    '</div>'
            }
        }
    ];
    // 實體化VueRouter物件
    let router = new VueRouter({
        routes:url,
        mode:'history' // 清除路徑
    });
    router.beforeEach(function (to, from, next) {
        console.log(to); // 跳轉到哪里
        console.log(from); // 從哪來
        console.log(next); // 下一步做什么
        // 直接路徑判斷
        // if(to.path == "/user"){
        //     next("/login");
        // }
        // 使用meta判斷(配置方便)
        if(to.meta.required_login){
            next("login");
        }
        next();
    });
    // router.afterEarch(function(to, from){
        // 智能識別路由要去哪和從哪來,一般用于獲取路由從哪來
    // });
    // 把VueRouter的實體化物件注冊到Vue的跟實體
    const app = new Vue({
        el:"#app",
        router:router
    })
</script>
</body>
</html>

5、子路由的注冊:靜態路由

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    <!-- 路由系結:to -->
    <router-link to="/">首頁</router-link>
    <router-link to="/course">課程</router-link>
    <router-link to="/course/detail">課程詳情</router-link>
    <router-view></router-view>
</div>
<script>
    // 定義路由匹配規則
    let url = [
        {
            path:"/",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>首頁組件</h1>' +
                    '</div>'
            }
        },
        {
            path:"/course",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>課程組件</h1>' +
                    '</div>'
            }
        },
        {
            path:"/course/detail",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>課程詳情組件</h1>' +
                        '<hr>' +
                        '<router-link to="/course/brief">課程概述</router-link> ' +
                        ' <router-link to="/course/chapter">課程章節</router-link>' +
                        '<router-view></router-view>' +
                    '</div>'
            },
            children:[
                {
                    path:"/course/brief",
                    component:{
                        template:'' +
                            '<div>' +
                                '<h1>課程概述組件</h1>' +
                            '</div>'
                    }
                },{
                    path:"/course/chapter",
                    component:{
                        template:'' +
                            '<div>' +
                                '<h1>課程章節組件</h1>' +
                            '</div>'
                    }
                },
            ]
        }
    ];
    // 實體化VueRouter物件
    let router = new VueRouter({
        routes:url
    });
    // 把VueRouter的實體化物件注冊到Vue的跟實體
    const app = new Vue({
        el:"#app",
        router:router
    })
</script>
</body>
</html>

6、子路由的注冊:動態路由

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    <!-- 路由系結:to -->
    <router-link to="/">首頁</router-link>
    <router-link to="/course">課程</router-link>
    <router-link to="/course/detail">課程詳情</router-link>
    <router-view></router-view>
</div>
<script>
    // 定義路由匹配規則
    let url = [
        {
            path:"/",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>首頁組件</h1>' +
                    '</div>'
            }
        },
        {
            path:"/course",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>課程組件</h1>' +
                    '</div>'
            }
        },
        {
            path:"/course/detail",
            redirect:{name:'brief'}, // 重定向子路由,實作默認頁面顯示
            component:{
                template:'' +
                    '<div>' +
                        '<h1>課程詳情組件</h1>' +
                        '<hr>' +
                        '<router-link :to="{name:\'brief\'}">課程概述</router-link> ' +
                        '<router-link to="/course/chapter">課程章節</router-link>' +
                        '<router-view></router-view>' +
                    '</div>'
            },
            children:[
                {
                    path:"brief",
                    name:"brief",
                    component:{
                        template:'' +
                            '<div>' +
                                '<h1>課程概述組件</h1>' +
                            '</div>'
                    }
                },{
                    path:"/course/chapter",
                    name:"chapter",
                    component:{
                        template:'' +
                            '<div>' +
                                '<h1>課程章節組件</h1>' +
                            '</div>'
                    }
                },
            ]
        }
    ];
    // 實體化VueRouter物件
    let router = new VueRouter({
        routes:url
    });
    // 把VueRouter的實體化物件注冊到Vue的跟實體
    const app = new Vue({
        el:"#app",
        router:router
    })
</script>
</body>
</html>

7、命名的路由視圖

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    <!-- 路由系結:to -->
    <router-link to="/">首頁</router-link>
    <router-link to="/course">課程</router-link>
    <router-link to="/user">用戶</router-link>
    <router-view name="head"></router-view>
    <router-view name="footer"></router-view>
    <router-view></router-view>
</div>
<script>
    // 定義路由匹配規則
    let url = [
        {
            path:"/",
            component:{
                template:'' +
                    '<div>' +
                        '<h1>首頁組件</h1>' +
                    '</div>',
            }
        },
        {
            path:"/course",
            component:{
                template:'<div><h1>課程組件</h1></div>'
            }
        },
        {
            path:"/user",
            components:{
                head:{
                    template:'' +
                    '<div>' +
                        '<h1>用戶head</h1>' +
                    '</div>'
                },
                footer:{
                    template:'' +
                    '<div>' +
                        '<h1>用戶footer</h1>' +
                    '</div>'
                }
            }
        }
    ];
    // 實體化VueRouter物件
    let router = new VueRouter({
        routes:url,
        mode:'history' // 清除路徑
    });
    router.beforeEach(function (to, from, next) {
        next();
    });
    // 把VueRouter的實體化物件注冊到Vue的跟實體
    const app = new Vue({
        el:"#app",
        router:router
    })
</script>
</body>
</html>

8、Vue的路由:

注冊:
-- 定義一個匹配規則物件
let url = [
{
path:"/",
component:{}

? }
? ]
? -- 實體化VueRouter物件 并把匹配規則注冊進去
? let router = new VueRouter({
? routes:url
? })
? -- 把VueRouter實體化物件注冊到Vue的根實體
? const app = new Vue({
? el:""
? })
? -- router-link
? -- router-view

子路由的注冊
-- 在父路由里注冊children:[{},{}]
-- 在父路由對應的組件里的template里寫 router-link router-view

路由的名命
-- name
-- 注意 to 一定動態系結 :to=" {name:' '} "

路由的引數
this.$route.params.xxxx
this.$route.query.xxxx

自定義路由
this.$router.push("/course")
this.$router.push({name:' ', params:{ },query:{}})

路由的鉤子函式
router.beforeEach(function(to, from, next){
to 路由去哪
from 路由從哪來
next 路由接下來要做什么
}) # 一般用于攔截
router.afterEach(function(to, from){
}) # 一般用于獲取

注意
$route 路由的所有資訊組成的物件
$router VueRouter 實體化物件
redirect 路由的重定向

四、Vue的生命周期

Vue生命周期的鉤子函式:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
    {{name}}
</div>
<script>
    const app = new Vue({
        el:"#app",
        data:{
            name:"eric"
        },
        methods:{
            init:function(){
                console.log(123)
            }
        },
        beforeCreate(){
            console.group("BeforeCreate");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        },
        created(){
            console.group("Created");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        },
        beforeMount(){
            console.group("BeforeMount");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        },
        mounted(){
            console.group("Mounted");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        },
        beforeUpdate(){
            console.group("BeforeUpdate");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        },
        updated(){
            console.group("Updated");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        },
        beforeDestroy(){
            console.group("BeforeDestroy");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        },
        destroyed(){
            console.group("Destroyed");
            console.log(this.$el);
            console.log(this.name);
            console.log(this.init);
        }
    })
</script>
</body>
</html>

Vue的生命周期的鉤子 LifeCycle hooks

資料監聽之前:beforeCreate();

監聽資料變化:created();

虛擬dom加載完成前:beforeMount();

頁面真實加載完成后:mounted();

資料改變前執行的函式:beforeUpdate();

資料改變后執行的函式:updated();

Vue實體銷毀前:beforeDestroy();

Vue實體銷毀后:destroyed()s

五、Vue-cli腳手架

作用:腳手架幫助搭建Vue專案

下載(下載到全域):npm i vue-cli -g

用vue-cli搭建專案:vue init webpack 專案名稱

啟動專案:
cd到專案目錄下:npm run dev

vue-cli專案目錄:

? build 打包后存放的所有檔案包括組態檔
? config 組態檔
? node_models 依賴包
? src 作業目錄
? static 靜態檔案
? index.html 單頁面
? pckage.json 存放所有專案資訊

路由的解耦程序:

? 下載 npm i vue-router
? 匯入 import VueRouter from 'vue-router'
? Vue.use(VueRouter)
? 定義匹配規則url
? 實體化物件VueRouter
? 把VueRouter物件注冊到Vue的跟實體中

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/234180.html

標籤:HTML5

上一篇:職場小白,請各位指點迷津

下一篇:JavaScript的DOM,BOM簡單介紹

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • vue移動端上拉加載

    可能做得過于簡單或者比較low,請各位大佬留情,一起探討技術 ......

    uj5u.com 2020-09-10 04:38:07 more
  • 優美網站首頁,頂部多層導航

    一個個人用的瀏覽器首頁,可以把一下常用的網站放在這里,平常打開會比較方便。 第一步,HTML代碼 <script src=https://www.cnblogs.com/szharf/p/"js/jquery-3.4.1.min.js"></script> <div id="navigate"> <ul> <li class="labels labels_1"> ......

    uj5u.com 2020-09-10 04:38:47 more
  • 頁面為要加<!DOCTYPE html>

    最近因為寫一個js函式,需要用到$(window).height(); 由于手寫demo的時候,過于自信,其實對前端方面的認識也不夠體系,用文本檔案直接敲出來的html代碼,第一行沒有加上<!DOCTYPE html> 導致了$(window).height();的結果直接是整個document的高 ......

    uj5u.com 2020-09-10 04:38:52 more
  • WordPress網站程式手動升級要做好資料備份

    WordPress博客網站程式在進行升級前,必須要做好網站資料的備份,這個問題良家佐言是遇見過的;在剛開始接觸WordPress博客程式的時候,因為升級問題和博客網站的修改的一些嘗試,良家佐言是吃盡了苦頭。因為購買的是西部數碼的空間和域名,每當佐言把自己的WordPress博客網站搞到一塌糊涂的時候 ......

    uj5u.com 2020-09-10 04:39:30 more
  • WordPress程式不能升級為5.4.2版本的原因

    WordPress是一款個人博客系統,受到英文博客愛好者和中文博客愛好者的追捧,并逐步演化成一款內容管理系統軟體;它是使用PHP語言和MySQL資料庫開發的,用戶可以在支持PHP和MySQL資料庫的服務器上使用自己的博客。每一次WordPress程式的更新,就會牽動無數WordPress愛好者的心, ......

    uj5u.com 2020-09-10 04:39:49 more
  • 使用CSS3的偽元素進行首字母下沉和首行改變樣式

    網頁中常見的一種效果,首字改變樣式或者首行改變樣式,效果如下圖。 代碼: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, ......

    uj5u.com 2020-09-10 04:40:09 more
  • 關于a標簽的講解

    什么是a標簽? <a> 標簽定義超鏈接,用于從一個頁面鏈接到另一個頁面。 <a> 元素最重要的屬性是 href 屬性,它指定鏈接的目標。 a標簽的語法格式:<a href=https://www.cnblogs.com/summerxbc/p/"指定要跳轉的目標界面的鏈接">需要展示給用戶看見的內容</a> a標簽 在所有瀏覽器中,鏈接的默認外觀如下: 未被訪問的鏈接帶 ......

    uj5u.com 2020-09-10 04:40:11 more
  • 前端輪播圖

    在需要輪播的頁面是引入swiper.min.js和swiper.min.css swiper.min.js地址: 鏈接:https://pan.baidu.com/s/15Uh516YHa4CV3X-RyjEIWw 提取碼:4aks swiper.min.css地址 鏈接:https://pan.b ......

    uj5u.com 2020-09-10 04:40:13 more
  • 如何設定html中的背景圖片(全屏顯示,且不拉伸)

    1 <style>2 body{background-image:url(https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture); 3 background-size:cover;background ......

    uj5u.com 2020-09-10 04:40:16 more
  • Java學習——HTML詳解(上)

    HTML詳解 初識HTML Hyper Text Markup Language(超文本標記語言) 1 <!--DOCTYPE:告訴瀏覽器我們要使用什么規范--> 2 <!DOCTYPE html> 3 <html lang="en"> 4 <head> 5 <!--meta 描述性的標簽,描述一些 ......

    uj5u.com 2020-09-10 04:40:33 more
最新发布
  • 我的第一個NPM包:panghu-planebattle-esm(胖虎飛機大戰)使用說明

    好家伙,我的包終于開發完啦 歡迎使用胖虎的飛機大戰包!! 為你的主頁添加色彩 這是一個有趣的網頁小游戲包,使用canvas和js開發 使用ES6模塊化開發 效果圖如下: (覺得圖片太sb的可以自己改) 代碼已開源!! Git: https://gitee.com/tang-and-han-dynas ......

    uj5u.com 2023-04-20 07:59:23 more
  • 生產事故-走近科學之消失的JWT

    入職多年,面對生產環境,盡管都是小心翼翼,慎之又慎,還是難免捅出簍子。輕則滿頭大汗,面紅耳赤。重則系統停擺,損失資金。每一個生產事故的背后,都是寶貴的經驗和教訓,都是專案成員的血淚史。為了更好地防范和遏制今后的各類事故,特開此專題,長期更新和記錄大大小小的各類事故。有些是親身經歷,有些是經人耳傳口授 ......

    uj5u.com 2023-04-18 07:55:04 more
  • 記錄--Canvas實作打飛字游戲

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 打開游戲界面,看到一個畫面簡潔、卻又富有挑戰性的游戲。螢屏上,有一個白色的矩形框,里面不斷下落著各種單詞,而我需要迅速地輸入這些單詞。如果我輸入的單詞與螢屏上的單詞匹配,那么我就可以獲得得分;如果我輸入的單詞錯誤或者時間過長,那么我就會輸 ......

    uj5u.com 2023-04-04 08:35:30 more
  • 了解 HTTP 看這一篇就夠

    在學習網路之前,了解它的歷史能夠幫助我們明白為何它會發展為如今這個樣子,引發探究網路的興趣。下面的這張圖片就展示了“互聯網”誕生至今的發展歷程。 ......

    uj5u.com 2023-03-16 11:00:15 more
  • 藍牙-低功耗中心設備

    //11.開啟藍牙配接器 openBluetoothAdapter //21.開始搜索藍牙設備 startBluetoothDevicesDiscovery //31.開啟監聽搜索藍牙設備 onBluetoothDeviceFound //30.停止監聽搜索藍牙設備 offBluetoothDevi ......

    uj5u.com 2023-03-15 09:06:45 more
  • canvas畫板(滑鼠和觸摸)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>canves</title> <style> #canvas { cursor:url(../images/pen.png),crosshair; } #canvasdiv{ bo ......

    uj5u.com 2023-02-15 08:56:31 more
  • 手機端H5 實作自定義拍照界面

    手機端 H5 實作自定義拍照界面也可以使用 MediaDevices API 和 <video> 標簽來實作,和在桌面端做法基本一致。 首先,使用 MediaDevices.getUserMedia() 方法獲取攝像頭媒體流,并將其傳遞給 <video> 標簽進行渲染。 接著,使用 HTML 的 < ......

    uj5u.com 2023-01-12 07:58:22 more
  • 記錄--短視頻滑動播放在 H5 下的實作

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 短視頻已經無數不在了,但是主體還是使用 app 來承載的。本文講述 H5 如何實作 app 的視頻滑動體驗。 無聲勝有聲,一圖頂百辯,且看下圖: 網址鏈接(需在微信或者手Q中瀏覽) 從上圖可以看到,我們主要實作的功能也是本文要講解的有: ......

    uj5u.com 2023-01-04 07:29:05 more
  • 一文讀懂 HTTP/1 HTTP/2 HTTP/3

    從 1989 年萬維網(www)誕生,HTTP(HyperText Transfer Protocol)經歷了眾多版本迭代,WebSocket 也在期間萌芽。1991 年 HTTP0.9 被發明。1996 年出現了 HTTP1.0。2015 年 HTTP2 正式發布。2020 年 HTTP3 或能正... ......

    uj5u.com 2022-12-24 06:56:02 more
  • 【HTML基礎篇002】HTML之form表單超詳解

    ??一、form表單是什么

    ??二、form表單的屬性

    ??三、input中的各種Type屬性值

    ??四、標簽 ......

    uj5u.com 2022-12-18 07:17:06 more