VUE入门学习

一、vue入门学习前准备

1、安装vue.js插件

VUE入门学习

当安装插件后无法new一个vue component文件时,需要进行配置

VUE入门学习

此时就可以new了,如下图

VUE入门学习

2、学习vue的入门demo

     ①、新建一个html,如下图

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
{{message}}
</div>

<!--导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<script>
    var vu=new Vue({
        el: "#app",
        data:{
            message: "hello,vue!!"
        }
    })
</script>
</body>
</html>

        ②、直接浏览器打开该html,message内容直接展示在div中

VUE入门学习

VUE入门学习

  ③、鼠标悬停查看动态绑定的提示信息!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <div>
        <span v-bind:title="message">
            鼠标悬停查看动态绑定的提示信息
        </span>

    </div>
</div>


<!--导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<script>
    var vu = new Vue({
        el: "#app",
        data: {
            message: "hello,vue!!"
        }
    })
</script>
</body>
</html>

效果如右图VUE入门学习

     ④、vue中的if判断

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <h1 v-if="flag">yes</h1>
    <h1 v-else>No</h1>
    <br>
    <h2 v-if="status==1">等于1</h2>
    <h2 v-else-if="status==2">等于2</h2>
    <h2 v-else>等于其他</h2>
</div>


<!--导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<script>
    var vu = new Vue({
        el: "#app",
        data: {
            flag: false,
            status: "2"
        }
    })
</script>
</body>
</html>

运行结果如右图VUE入门学习

⑤、VUE的for循环使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <li v-for="list in lists">
        {{list.title}}
    </li>

</div>


<!--导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<script>
    var vu = new Vue({
        el: "#app",
        data: {
                lists: [
                    {title: "我爱学java"},
                    {title: "我爱学VUE"}
                ]
        }
    })
</script>
</body>
</html>

运行后结果如右图VUE入门学习

⑥、vue的事件绑定

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <button v-on:click="clicks">
        vue事件绑定
    </button>

</div>


<!--导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<script>
    var vu = new Vue({
        el: "#app",
        data: {
            tite: "学习vue!!!"
        },
        methods: {
            clicks: function(event){
               alert("我要"+this.tite)
            }
    }
    })
</script>
</body>
</html>

运行结果如右图VUE入门学习

上一篇:[CF#712Div2]A题Déjà Vu


下一篇:CF331E2 Deja Vu 图论