vue腳手架vue數據交互_學習Vue:3分鐘的交互式Vue JS教程

vue腳手架vue數據交互

Vue.js is a JavaScript library for building user interfaces. Last year, it started to become quite popular among web developers. It’s lightweight, relatively easy to learn, and powerful.

Vue.js是用于構建用戶界面JavaScript庫。 去年,它開始在Web開發人員中變得非常流行。 它輕巧,易于學習且功能強大。

In the three minutes that Medium says it will take you to read this article, you’ll be equipped to start building basic Vue apps. With each segment, I’ve also included an interactive Scrimba screencast, where you can watch me explain the concepts and play around with the code yourself.

在Medium說的三分鐘內,您將需要閱讀本文,您將具備開始構建基本的Vue應用程序的能力。 在每個部分中,我還包括一個互動式Scrimba截屏,您可以在其中觀看我講解概念并親自使用代碼。

Let’s jump into it.

讓我們跳進去。

模板語法和數據 (Template syntax and data)

At the core of Vue.js is a straightforward template syntax which looks like this:

Vue.js的核心是簡單的模板語法,如下所示:

<div id="myApp">  {{ message }}  
</div>

Pair that with the following JavaScript snippet:

將其與以下JavaScript代碼段配對:

var myApp = new Vue({  el: '#myApp',  data: {  message: 'Hello world!'  }  
})

And it’ll result in Hello world! being rendered on the page.

它將進入Hello World! 在頁面上呈現。

The el: #myApp part tells Vue to render the app inside the DOM element with the id of myApp. The data object is where you place you the data you want to use in your app. We’ve added only one key here, message, which we’re referencing to in our HTML like this: {{ message }}.

el: #myApp部分告訴Vue使用myApp的ID在DOM元素內渲染應用程序 data對象是放置要在應用程序中使用的數據的位置。 我們在此處僅添加了一個鍵message ,它在我們HTML中是這樣引用的: {{ message }}

Vue takes care of linking the data object to the DOM, so if the data changes, the page will be updated as well.

Vue負責將data對象鏈接到DOM,因此,如果數據發生更改,頁面也將被更新。

This is called declarative rendering. You simply specify what you want to update, and Vue takes care of how to do it.

這稱為聲明式渲染。 您只需指定要更新什么 ,Vue公司需要照顧怎么辦呢。

You can change the data can by doing this:

您可以通過執行以下操作來更改數據罐:

myApp.message = 'Some new value';

Here is a screencast which explains this exact concept:

這是一個截屏視頻,解釋了這個確切的概念:

指令 (Directives)

The next concept you’ll need to learn is directives. Directives are HTML attributes that are prefixed with v-, which indicates that they apply reactive behavior to the rendered DOM.

您需要學習的下一個概念是指令。 指令是帶有v-前綴HTML屬性,指示它們將React式行為應用于呈現的DOM。

Let’s say we only want to render something if a condition is true, and hide it if it’s false. Then we’ll use v-if.

假設我們只想在條件為true時渲染某些內容,而在條件為false時隱藏它。 然后,我們將使用v-if

In the HTML, it looks like this.

在HTML中,它看起來像這樣。

<div id="app">  <p v-if="seen">Now you see me</p>  
</div>

And some JavaScript:

還有一些JavaScript:

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

This will result in rendering out the Now you see me paragraph if seen in data is true. To hide the paragraph, you can set seen to false, like this:

如果在data seen的是真實的,這將導致呈現“ 立即看到我”段落 要隱藏該段落,可以將seen設置為false,如下所示:

app.seen = false;

app.seen = false;

Here is a screencast explaining the same concept:

這是解釋相同概念的截屏視頻:

There are many other directives, like v-for, v-on, v-bind and v-model.

還有許多其他指令,例如v-forv-on, v-bindv-model

處理用戶輸入 (Handling user input)

Another core directive you need to learn is v-on. It will hook up an event listener to the DOM element, so that you can handle user input. You specify the type of event after the colon. So v-on:click will listen for clicks.

您需要學習的另一個核心指令是v-on 。 它將事件監聽器連接到DOM元素,以便您可以處理用戶輸入。 您可以在冒號后面指定事件的類型。 因此, v-on:click將監聽點擊。

<div id="app">  <button v-on:click="myClickHandler">Click me!</button>  
</div>

myClickHandler refers to the key with the same name in the methods object. Needless to say, that’s the object where you place your app’s methods. You can have as many methods as you want.

myClickHandlermethods對象中引用具有相同名稱的鍵。 不用說,這就是放置應用程序方法的對象。 您可以根據需要使用多種方法。

var app = new Vue({  el: '#app',  methods: {  myClickHandler: function () {  console.log('button clicked!');  }  }  
})

This will result in button clicked being logged to the console when clicking the button.

這將導致按鈕單擊單擊按鈕時被記錄到控制臺。

Here is a screencast explaining the concept:

這是解釋此概念的截屏視頻:

綁在一起 (Tying it all together)

Now let’s create an example where we’re using both data and methods, tying together what we’ve learned up until now.

現在,讓我們創建一個示例,在此示例中,我們同時使用datamethods ,將到目前為止所學的知識聯系在一起。

<div id="app">  <p>{{ message }}</p>  <button v-on:click="changeMessage">Click me!</button>  
</div>

And the JavaScript:

和JavaScript:

var app = new Vue({  el: '#app',  data: {  message: 'Start message'  },  methods: {  changeMessage: function () {  this.message = 'The message has changed!'  }  }  
})

Initially, it’ll display out Start message on the page, however after the click it’ll display This message has changed instead.

最初,它將在頁面上顯示開始消息 ,但是單擊后將顯示此消息已更改

The this ?keyword refers to the Vue instance, the one we’ve called app. It is on this instance that our data lives, so we can refer to the message data through this.message.

this關鍵字引用Vue實例,我們將其稱為app 。 正是在這種情況下,我們的數據才得以生存,因此我們可以通過this.message引用message數據。

Check out this screencast explaining the concept.

查看此截屏視頻,以解釋概念。

And by that, you should know enough Vue.js to get started creating simple apps.

這樣一來,您應該了解足夠的Vue.js才能開始創建簡單的應用程序。

In the next tutorial, you’ll learn how to create Vue components. So be sure to follow this publication if you liked this article.

在下一個教程中,您將學習如何創建Vue組件。 因此,如果您喜歡本文,請確保遵循該出版物。

翻譯自: https://www.freecodecamp.org/news/learn-basic-vue-js-crash-course-guide-vue-tutorial-e3da361c635/

vue腳手架vue數據交互

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/395359.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395359.shtml
英文地址,請注明出處:http://en.pswp.cn/news/395359.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[JSOI2018]潛入行動

題解 一道思路不難但是寫起來很麻煩的樹形背包 我們發現每個節點有很多信息需要保留 所以就暴力的設\(f[u][j][0/1][0/1]\)表示點u的子樹分配了j個監察器,點u有沒有被控制,點u放沒放監察器 然后就分四種情況暴力討論就好了 注意背包的時候要卡常數 代碼 #include<cstdio>…

css。元素樣式、邊框樣式

1.外邊距  margin 縮寫形式&#xff1a; margin&#xff1a;上邊距  右邊距  下邊距  左邊距 margin&#xff1a;上下邊距  左右邊距 margin&#xff1a;上邊距  左右邊距  下邊距 2.內邊距  padding 縮寫形式&#xff1a; padding&#xff1a;上邊距  右邊距…

html文本對齊6,HTML對齊文本

我要像以下列方式顯示頁面上的文本&#xff1a;HTML對齊文本My Text: Text HereMy Text: More Text Here.........................................................Text from line above continued here.我有以下的標記只是為了測試&#xff1a;body {font-family: arial;}fo…

vue底部跳轉_詳解Vue底部導航欄組件

不多說直接上代碼 BottomNav.vue&#xff1a;{{item.name}}export default{props:[idx],data(){return {items:[{cls:"home",name:"首頁",push:"/home",icon:"../static/home.png",iconSelect:"../static/home_select.png"}…

Android Studio環境搭建

Android Studio環境搭建 個人博客 歡迎大家多多關注該獨立博客。 ###[csdn博客]&#xff08;http://blog.csdn.net/peace1213&#xff09; 一直想把自己的經驗分享出來&#xff0c;記得上次寫博客還是ok6410的筆記。感覺時代久遠啊。記得那個時候我還一心想搞硬件了。如今又一次…

hacktoberfest_Hacktoberfest和其他有趣的事情將在本周末在freeCodeCamp

hacktoberfestby Quincy Larson昆西拉爾森(Quincy Larson) Hacktoberfest和其他有趣的事情將在本周末在freeCodeCamp (Hacktoberfest and other fun things going on this weekend at freeCodeCamp) Earlier this month, the freeCodeCamp community turned 3 years old. And …

C# 動態創建數據庫三(MySQL)

前面有說明使用EF動態新建數據庫與表&#xff0c;數據庫使用的是SQL SERVER2008的&#xff0c;在使用MYSQL的時候還是有所不同 一、添加 EntityFramework.dll &#xff0c;System.Data.Entity.dll &#xff0c;MySql.Data, MySql.Data.Entity.EF6 注意&#xff1a;Entity Frame…

iOS開發Swift篇—(七)函數(1)

一、函數的定義 &#xff08;1&#xff09;函數的定義格式 1 func 函數名(形參列表) -> 返回值類型 { 2 // 函數體... 3 4 } &#xff08;2&#xff09;形參列表的格式 形參名1: 形參類型1, 形參名2: 形參類型2, … &#xff08;3&#xff09;舉例&#xff1a;計算2個…

如何用計算機管理員權限,教你電腦使用代碼添加管理員權限的詳細教程

我們在使用電腦運行某些軟件的時候&#xff0c;可能需要用到管理員權限才能運行&#xff0c;通常來說直接點擊右鍵就會有管理員權限&#xff0c;但最近有用戶向小編反饋&#xff0c;在需要管理員權限的軟件上點擊右鍵沒有看到管理員取得所有權&#xff0c;那么究竟該如何才能獲…

activiti 5.22的demo運行

activiti 5.22的demo運行 從github上clon下來的activiti項目,運行demo項目activiti-webapp-explorer2時&#xff0c;在使用到流程設計工作區&#xff0c;選取activiti modeler作為設計器的時候報錯。 從下面的報錯信息中發現&#xff0c;請求路徑http://localhost:8080/activit…

宣布JavaScript 2017狀況調查

by Sacha Greif由Sacha Greif 宣布JavaScript 2017狀況調查 (Announcing the State of JavaScript 2017 Survey) 讓我們找出去年以來發生的變化&#xff01; (Let’s find out what’s changed since last year!) In a hurry? You can take the survey here.匆忙&#xff1f;…

內是不是半包圍結構_輕鋼別墅的體系結構

一、輕鋼別墅介紹1、輕鋼別墅的屋面系統輕鋼別墅屋面系統是由屋架、結構OSB面板、防水層、輕型屋面瓦&#xff08;金屬或瀝青瓦&#xff09;組成的。輕鋼結構的屋面&#xff0c;外觀可以有多種組合。材料也有多種。在保障了防水這一技術的前提下&#xff0c;外觀有了許多的選擇…

JavaScript call()函數的應用

call([thisObj[,arg1[, arg2[, [,.argN]]]]]) call 方法可以用來代替另一個對象調用一個方法。call 方法可將一個函數的對象上下文從初始的上下文改變為由 thisObj 指定的新對象。 thisObj 可選項。將被用作當前對象的對象。 arg1, arg2, , argN 可選項。將被傳遞方法參數序…

hive 去重 字符串_hive函數

Hive是建立在 Hadoop 上的數據倉庫基礎架構,定義了簡單的類 SQL 查詢語言(HQL)函數分類&#xff1a;簡單內置函數&#xff1a;數學函數&#xff0c;字符函數&#xff0c;日期函數&#xff0c;條件函數&#xff0c;聚合函數。高級內置函數&#xff1a;行列轉換函數&#xff0c;分…

python word

代碼&#xff1a; 1 #codingutf-82 __author__ zhm3 from win32com import client as wc4 import os5 import time6 import random7 import MySQLdb8 import re9 def wordsToHtml(dir):10 #批量把文件夾的word文檔轉換成html文件11 #金山WPS調用&#xff0c;搶先版的用KWPS&a…

aws lambda_如何為AWS Lambda實施日志聚合

aws lambdaby Yan Cui崔燕 如何為AWS Lambda實施日志聚合 (How to implement log aggregation for AWS Lambda) During the execution of a Lambda function, whatever you write to stdout (for example, using console.log in Node.js) will be captured by Lambda and sent…

【Python3爬蟲】為什么你的博客沒人看呢?

我相信對于很多愛好和習慣寫博客的人來說&#xff0c;如果自己的博客有很多人閱讀和評論的話&#xff0c;自己會非常開心&#xff0c;但是你發現自己用心寫的博客卻沒什么人看&#xff0c;多多少少會覺得有些傷心吧&#xff1f;我們今天就來看一下為什么你的博客沒人看呢&#…

泰安高考2021成績查詢,泰安高考成績查詢入口2021

高考結束之后&#xff0c;為了方便大家進行高考成績的查詢&#xff0c;下面跟著出國留學網小編來一起看看“泰安高考成績查詢入口2021”&#xff0c;僅供參考&#xff0c;希望對大家有幫助。2021山東高考成績查詢時間及志愿填報時間根據山東2021年夏季高考須知&#xff0c;2021…

用GitHub Issue取代多說,是不是很厲害?

2019獨角獸企業重金招聘Python工程師標準>>> 摘要: 別了&#xff0c;多說&#xff0c;擁抱Gitment。 2017年6月1日&#xff0c;多說正式下線&#xff0c;這多少讓人感覺有些遺憾。在比較了多個博客評論系統&#xff0c;我最終選擇了Gitment作為本站的博客評論系統&a…

mysql延時優化教程_Mysql優化之延遲索引和分頁優化_MySQL

什么是延遲索引&#xff1f;使用索引查詢出來數據&#xff0c;之后把查詢結果和同一張表中數據進行連接查詢&#xff0c;進而提高查詢速度!分頁是一個很常見功能&#xff0c;select ** from tableName limit ($page - 1 ) * $n ,$n通過一個存儲過程插入10000條數據進行測試&…