微信小程序开发

01-vue体验

2019-12-24  本文已影响0人  我是要成为大神的男人
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue学习</title>
    <!-- 生产环境版本,优化了尺寸和速度 -->
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>

<!--1-->
<div id="app">
    {{ message }}
</div>

<!--v-bind: title 特性和 Vue 实例的 message 属性保持一致-->
<div id="app-2">
  <span v-bind:title="message">
    鼠标悬停几秒钟查看此处动态绑定的提示信息!
  </span>
</div>
<!--v-if: 条件判断-->
<div id="app-3">
    <p v-if="seen">现在你看到我了</p>
</div>

<!--v-for: 指令可以绑定数组的数据来渲染一个项目列表-->
<div id="app-4">
    <ul>
        <li v-for="todo in todos">
            {{ todo.text }}
        </li>
    </ul>
</div>

<!--v-on: 指令添加一个事件监听器,调用在 Vue 实例中定义的方法-->
<div id="app-5">
    <p>{{ message }}</p>
    <button v-on:click="reverseMessage">反转消息</button>
</div>

<!--v-model 指令: 实现表单输入和应用状态之间的双向绑定-->
<div id="app-6">
    <p>{{ message }}</p>
    <input v-model="message">
</div>


<script>
    <!--1-->
    var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!'
        }
    })

    var app2 = new Vue({
        el: '#app-2',
        data: {
            message: '页面加载于 ' + new Date().toLocaleString()
        }
    })
    console.log(new Date().toLocaleString());

    var app3 = new Vue({
        el: '#app-3',
        data: {
            seen: true
        }
    })

    var app4 = new Vue({
        el: '#app-4',
        data: {
            todos: [
                { text: '学习 JavaScript' },
                { text: '学习 Vue' },
                { text: '整个牛项目' }
            ]
        }
    })
    app4.todos.push({ text: '新项目' });

    var app5 = new Vue({
        el: '#app-5',
        data: {
            message: 'Hello Vue.js!'
        },
        methods: {
            reverseMessage: function () {
                this.message = this.message.split('').reverse().join('')
            }
        }
    })

    var app6 = new Vue({
        el: '#app-6',
        data: {
            message: 'Hello Vue!'
        }
    })
    console.log(app6.message);

</script>

</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读