• vue入门 0 小demo (挂载点、模板、实例)


    vue入门 0 小demo  (挂载点、模板) 

       用直接的引用vue.js

      首先 讲几个基本的概念

     1、挂载点即el:vue 实例化时 元素挂靠的地方。

      2.模板 即template:vue 实例化时挂载点 下赋值的模板。

      3.赋值时 的符号 有 插值表达式 {{msg}}  、 v-text="msg" 、v-html="msg"  类似于css 的写法

      4.实例 即数据:data:{msg:'hello world!'}

      4.事件表示:v-on:click="handleclick" ,vue 指令点击时的方法handleclick,  v-on:click 简写@click

        methods: { handleclick:function () {  this.msg='world';}

     5. 属性绑定 v-bind 简写:bind  or :     v-bind:title="title1"

    下面为代码

        效果为:显示 hello world ,点击时 变为world

    <!DOCTYPE html>
    <html lang="cn">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src="/vuejs/vue.js"></script>
       
    </head>
    <body>
      <div id="app">  <!--挂载点-->
        <!-- <p>{{msg}}</p> --><!--模板-->  <!--{{msg}} 为插值表达式 == v-text='msg' v-html="msg"-->
        <!-- <p v-text="msg"></p> -->
        <!-- <p v-html="msg"></p> -->
        <div v-on:click="handleclick">{{msg}}</div>
      </div>  
    </body>
    <script>
      new Vue({
        el:'#app',
        // template:'<p>{{msg}}</p>',
        data:{
          msg:'hello world!'
        },
        methods: {
            handleclick:function () {
                this.msg='world';
            }
        },
      });
    </script>
    </html>

     02属性和双向绑定

       知识点:v-bind:title 、v-model

     显示效果:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src="/vuejs/vue.js"></script>
    </head>
    <body>
        <div id="app">
            <!-- <div title="this is hello world">{{msg}}</div> -->

         <!-- <div title="this is hello world">{{msg}}</div> -->
        <div v-bind:title="title1">{{msg}}</div> <!--数据项属性绑定 :bind=v-bind: -->
        <div :title="title">{{msg}}</div> <!--数据项属性绑定 :bind=v-bind: -->
        <input v-model="content"/>

             <div>{{content}}</div>
        </div>
        <script>
         new  Vue({
             el:'#app',
             template:'',
             data:{
                msg:'hello world',
                title1:'this is hello world',
                content:'世界你好!'
             },
             methods: {
                 
             },
         });
        </script>
    </body>
    </html>

             

  • 相关阅读:
    linux安装 Android Studio详细教程,支持性较差,需要安装最新底层库内核的linux
    QT、QTE、qtopia区别
    Sublime Text 有哪些使用技巧
    华为5700交换机通过外部开源protal和本地aaa用户认证的一些问题
    离奇“undefined reference”错误分析与解决方案
    GNU工具链学习笔记
    gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
    揭开Linux操作系统的Swap交换区之谜
    invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
    学习JavaScript
  • 原文地址:https://www.cnblogs.com/laopo/p/11071660.html
Copyright © 2020-2023  润新知