Vue基礎---->VueJS的使用(一)

來源:互聯網
上載者:User

標籤:

  Vue.js是一個構建資料驅動的web介面的庫。它的目標是通過儘可能簡單的API 實現響應的資料繫結和組合的視圖組件,今天我們就開始vue.js的學習。

vue的安裝及使用

一、vue的:http://vuejs.org/js/vue.js

二、vue的第一個例子:

項目的結構如下,引入vue.js

vue1.html的代碼:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>vue1</title>    <script type="text/javascript" src="../vue.js"></script></head><body>    <div id="app">        <p>{{ message }}</p>        <input type="text" name="message" v-model="message" />    </div>    <script type="text/javascript" src="js/vue1.js"></script></body></html>

vue1.js的代碼:

var app = new Vue({    el: ‘#app‘,    data: {        message: "hello world"    }});

啟動並執行效果如下:

注意:

  • el: ‘#app‘ 就是管理id為app的部分。
  • vue1.js的引入在頁面代碼的後面,否則在某些瀏覽器上會出現找不到#app的元素的錯誤。

 

vue的簡單使用

以下的所有例子都是基於上述的例子的。這裡唯寫增加的代碼

 一、列表的渲染:v-for的使用

在<div id="app">中加入以下代碼:

<ul>    <li v-for="person in persons">      {{ person.name }} loves {{person.love}}    </li></ul>

在vue1.js的data中加入以下代碼:

persons: [    {name: "huhx", love: "code"},    {name: "chenhui", love: "book"}]

運行效果如下:

二、處理輸入: v-on:click的使用

在<div id="app">中加入以下代碼:

<button v-on:click="changeContent(‘huhx‘)">Click on!</button>

 在vue1.js中加入以下代碼:

methods: {    changeContent: function(element) {        this.message = "I love " + element;    }}

 

友情連結
  • vue的官方教程:http://cn.vuejs.org/guide/index.html
  • vue的官方api:  http://cn.vuejs.org/api/

 

Vue基礎---->VueJS的使用(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.