Vue.js 学习之路(一)

Vue.js 学习之路(一)

  1. (Demo) Hello Vue!

  2. Vue.js CDN
    https://www.bootcdn.cn/

  3. 插值语法{{msg}},数据,js表达式

  4. 指令:@click(点击事件),v-bind:href(事件绑定)

  5. 计算属性:computed

  6. 侦听器:watch

Vue.js 学习之路(一)_第1张图片

index.html

<html>

<head>
    <link rel="stylesheet" href="index.css">
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>

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

    <script src="index.js"></script>
</body>

</html>

index.css

html,
body {
    margin: 5px;
    padding: 0;
    color: blueviolet
}

index.js

new Vue({
    el: '#app',
    data: {
        msg: 'hello vue!!!',
    },
})

Vue.js 学习之路(一)_第2张图片
index.html

<html>

<head>
    <link rel="stylesheet" href="index.css">
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>

    <div id="app">
        <div>
            {{ msg }}
        </div>
        <div v-html="template">
            {{template}}
        </div>
        <div>
            <a v-bind:href="url">Github</a>
            <button type="button" @click="submit()">plus num</button>
            {{counter}}
        </div>

    </div>

    <script src="index.js"></script>
</body>

</html>

index.css

html,
body {
    margin: 5px;
    padding: 0;
    color: blueviolet
}

index.js

new Vue({
    el: '#app',
    data: {
        msg: 'hello vue!!!',
        counter: 0,
        template: "
Dream big
"
, url: "https://github.com/ceezyyy", }, methods: { submit: function () { this.counter++ } } })

Vue.js 学习之路(一)_第3张图片
index.html

<html>

<head>
    <link rel="stylesheet" href="index.css">
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>

    <div id="app">
        <p>
            {{msg1}}
        </p>
        <div>
            {{ msg }}
        </div>
        <div v-html="template">
            {{template}}
        </div>
        <div>
            <a v-bind:href="url">Github</a>
            <button type="button" @click="submit()">plus num</button>
            {{counter}}
        </div>

    </div>

    <script src="index.js"></script>
</body>

</html>

index.css

html,
body {
    margin: 5px;
    padding: 0;
    color: blueviolet
}

index.js

let app=new Vue({
    el: '#app',
    data: {
        msg: 'hello vue!!!',
        another:'another hello vue!!',
        counter: 0,
        template: "
Dream big
"
, url: "https://github.com/ceezyyy", }, watch:{ msg:function(newval,oldvar){ console.log('newval is:'+newval), console.log('oldvar is:'+oldvar) } }, computed:{ msg1:function(){ return 'computed: '+this.msg+this.another } }, methods: { submit: function () { this.counter++ } } })

Vue.js 学习之路(一)_第4张图片

你可能感兴趣的:(前端)