zoukankan      html  css  js  c++  java
  • 简单的Vue示例

    一、在项目目录/src/components/下新建Test.vue文件,内容如下:

    <template></template>

    <template>
      <div id="firstVue">
            <input type="number" v-model.number="my_step" />
            <button @click="clickButton">Add</button>
            <p>{{total_res}}</p>
            <div id="result">{{result}}</div>
      </div>
    </template>

    <script></script>

    <script>
      export default {
        name: 'Test.vue',
        data(){
          return {
            my_total: 0,
            my_step: 1,
            total_res: 1,
            result: ''
          }
        },
        methods:{
            clickButton:function(){
                this.my_total = this.my_total + this.my_step,
                this.total_res = this.my_total + this.my_step,
                this.result = '您点击了相加按钮,数值变为了'+this.my_total+'+'+this.my_step+'='+this.total_res
            }
        }
      }
    
    </script>

    <style></style>

    <style>
      #firstVue{
        width: 300px;
        height: 200px;
        background-color: #2C3E50;
      }
      #firstVue input{
        width: 150px;
        height: 25px;
        background-color: #ffffff;
        padding: 5px 5px;
      }
      #firstVue button{
        width: 50px;
        height: 30px;
        border-color: #2C3E50;
      }
      #firstVue p{
        background-color: #FFFFFF;
      }
      #result{
        background-color: #FFFFFF;
        font-size: 12px;
        font-color: red;
      }
    </style>

    二、在/src/router/index.js加上页面路由:

    import Vue from 'vue'
    import Router from 'vue-router'
    import HelloWorld from '@/components/HelloWorld'
    import SayHi from '@/components/SayHi'
    import Test from '@/components/Test'
    
    Vue.use(Router)
    
    export default new Router({
      routes: [
        {
          path: '/',
          name: 'HelloWorld',
          component: HelloWorld
        },
        {
          path: '/say_hi',
          name: 'SayHi',
          component: SayHi
        },
        {
          path: '/test',
          name: 'Test',
          component: Test
        }
      ]
    })

    三、执行npm  run dev,访问:http://localhost:8080/#/test,如下:

    点击Add按钮,可以看到执行结果,如下图:

  • 相关阅读:
    Eclipse工作间的基本配置。
    多态的 好处和弊端。
    线程转换状态。
    成员内部类如何访问。
    实现runnable接口启动线程相比继承Thread类启动线程的优点。
    Java中的命名规范。
    内部类的访问特点。
    那天无意间又看到一篇关于心流的文章
    科技爱好者周刊139
    形势与政策 期末考试
  • 原文地址:https://www.cnblogs.com/phperlinxinlan/p/13651813.html
Copyright © 2011-2022 走看看