vue2.0的學習

?vue-router

除了使用?<router-link>?創建 a 標簽來定義導航鏈接,我們還可以借助 router 的實例方法,通過編寫代碼來實現。

1)router.push(location)

這個方法會向 history 棧添加一個新的記錄,所以,當用戶點擊瀏覽器后退按鈕時,則回到之前的 URL。

當你點擊?<router-link>?時,這個方法會在內部調用,所以說,點擊?<router-link :to="...">?等同于調用router.push(...)

2)router.replace(location)

跟?router.push?很像,唯一的不同就是,它不會向 history 添加新記錄,而是跟它的方法名一樣 —— 替換掉當前的 history 記錄。

點擊<router-link :to="..." replace>等同于調用router.replace(...)

?

vue組件

注冊

1)全局注冊

復制代碼
//app.js
Vue.component('ttModal', Vue.asyncComponent('Common','ttModal'));
//ttModal.html <div class="tt-modal-wrapper"> <div class="modal-mask" v-bind:class="{'in': isModalIn}" v-on:click="modalClose"></div> <div class="modal-content" v-bind:class="{'in': isModalIn}"> modal-content. <slot name="content"></slot> </div> </div> //topicLeft.html <tt-modal?v-if="isShowCreateTopic" v-on:close="isShowCreateTopic = false"> <div slot="content">topicLeft.</div> </tt-modal>
復制代碼

渲染后:

復制代碼
//ttModal.html
methods: {modalClose: function(e) { if(this.$el.contains(e.target)) {
       //vm.$el:Vue 實例使用的根 DOM 元素 this.$emit('close');
       //vm.$emit:觸發當前實例上的事件即close事件 } } }
復制代碼

<slot>?元素可以用一個特殊的屬性?name?來配置如何分發內容。多個 slot 可以有不同的名字。具名 slot 將匹配內容片段中有對應?slot?特性的元素。

2)局部注冊

 ?通過使用組件實例選項注冊,可以使組件僅在另一個實例/組件的作用域中可用。

使用組件時,大多數可以傳入到 Vue 構造器中的選項可以在注冊組件時使用,有一個例外:?data?必須是函數。

復制代碼
//project.js
components: {"projectDetail": Vue.asyncComponent('Project', 'projectDetail', 'Project/projectDetail/projectDetail')
},//project.html <project-detail></project-detail>
復制代碼

?  Vue.js是數據驅動的,這使得我們并不需要直接操作DOM,如果我們不需要使用jQuery的DOM選擇器,就沒有必要引入jQuery。vue-resource是Vue.js的一款插件,它可以通過XMLHttpRequest或JSONP發起請求并處理響應。也就是說,$.ajax能做的事情,vue-resource插件一樣也能做到,而且vue-resource的API更為簡潔。另外,vue-resource還提供了非常有用的inteceptor功能,使用inteceptor可以在請求前和請求后附加一些行為,比如使用inteceptor在ajax請求時顯示loading界面。

復制代碼
<div class="itemAddRow clearfix"> <i>項目名</i> <textarea v-model="projectName" placeholder="請輸入項目名" style="height:32px;"></textarea> </div> <div class="itemAddRow clearfix"> <i>項目描述</i> <textarea v-model="projectDescription" placeholder="請輸入項目描述" style="height:150px;"></textarea> </div> <div class="itemAddRow clearfix"> <i>項目狀態</i> <div> <input type="radio" name="projectStatus" value="1" v-model="projectStatus">開發中&nbsp;&nbsp; <input type="radio" name="projectStatus" value="2" v-model="projectStatus">已發布 &nbsp;&nbsp; <input type="radio" name="projectStatus" value="3" v-model="projectStatus">穩定&nbsp;&nbsp; <input type="radio" name="projectStatus" value="4" v-model="projectStatus">停止維護&nbsp;&nbsp; </div> </div> 
復制代碼
復制代碼
data: function() {return {projectName:'', projectDescription:'', projectStatus:1 } }, methods: { addProject:function(){ var projectName=this.projectName.trim(), projectDescription=this.projectDescription.trim(); if(projectName==''||projectDescription==''){ alert('請輸入完整的項目信息'); return; } var postData={ name:projectName, description:projectDescription, status:this.projectStatus, userId:this.$conf.userInfo.userId }; var self=this; Vue.http.post(this.$conf.API_createProject,postData).then(function(response) { var data=response.data; if(data.ReturnCode == '0000') { 
         //vm.$parent:父實例,如果當前實例有的話 self.$parent.$parent.isShowProjectAdd = false; } }); } }
復制代碼

?

組件實例的作用域是孤立的。這意味著不能并且不應該在子組件的模板內直接引用父組件的數據。

1)可以使用 props 把數據傳給子組件。

prop 是父組件用來傳遞數據的一個自定義屬性。子組件需要顯式地用props選項聲明 “prop”。

復制代碼
<!--taskAdd.html-->
<tt-popup top="10px" left="20px"> <div slot="content">users</div> </tt-popup> <!--ttPopup.html--> <div class="tt-popup" v-bind:style="{top:top,left:left}"> <slot name="content"></slot> </div>
復制代碼

?

//app.js
Vue.component('ttPopup', Vue.asyncComponent('Common','ttPopup'));//注冊組件 //ttPopup.html props: ['top','left'],

渲染后:

2)在子組件中使用this.$parent獲取父組件實例

?

插件通常會為Vue添加全局功能。

1)Vue.js 的插件應當有一個公開方法?install?。這個方法的第一個參數是?Vue?構造器?

2)通過全局方法 Vue.use(plugin) 使用插件

安裝 Vue.js 插件。如果插件是一個對象,必須提供?install?方法。如果插件是一個函數,它會被作為 install 方法。install 方法將被作為 Vue 的參數調用。

復制代碼
//1,添加實例方法
function plugin(Vue) {if(plugin.installed) { return; } Vue.prototype.$conf = conf; } if(typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); } //2,添加全局方法或屬性 function plugin(Vue) { if(plugin.installed) { return; } Vue.asyncComponent = asyncComponent; } if(typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); }
復制代碼

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

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

相關文章

mysql+url的配置參數詳解_MySql鏈接url參數詳解

mysql URL格式如下&#xff1a;jdbc:mysql://[host:port],[host:port].../[database][?參數名1][參數值1][&參數名2][參數值2]...MySQL在高版本需要指明是否進行SSL連接 在url后面加上 useSSLtrue 不然寫程序會有warning常用的幾個較為重要的參數&#xff1a;參數名…

Java LocalDate類| minus()方法與示例

LocalDate類isSupported()方法 (LocalDate Class isSupported() method) Syntax: 句法&#xff1a; public LocalDate minus(TemporalAmount t_amt);public LocalDate minus(long amt, TemporalUnit t_unit);isSupported() method is available in java.time package. isSuppo…

《Java EE 7精粹》—— 第3章 JSF 3.1 Facelets

本節書摘來異步社區《Java EE 7精粹》一書中的第2章&#xff0c;第2.1節&#xff0c;作者&#xff1a;【美】Arun Gupta&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 第3章 JSF JSF是基于Java的Web應用程序開發的服務器端用戶界面&#xff08;UI&#xf…

mysql5批處理_轉關于mysql5.5 的批處理討論(轉載)

MySql的JDBC驅動不支持批量操作(已結)MySql連接的url中要加rewriteBatchedStatements參數&#xff0c;例如String connectionUrl"jdbc:mysql://192.168.1.100:3306/test?rewriteBatchedStatementstrue";還要保證mysql JDBC驅的版本。MySql的JDBC驅動的批量插入操作性…

Java Duration類| isZero()方法與示例

持續時間類isZero()方法 (Duration Class isZero() method) isZero() method is available in java.time package. isZero()方法在java.time包中可用。 isZero() method is used to check whether this Duration object holds the value of length is 0 or not. isZero()方法用…

《C#多線程編程實戰(原書第2版)》——3.2 在線程池中調用委托

本節書摘來自華章出版社《C#多線程編程實戰&#xff08;原書第2版&#xff09;》一書中的第3章&#xff0c;第3.2節&#xff0c;作者&#xff08;美&#xff09;易格恩阿格佛溫&#xff08;Eugene Agafonov&#xff09;&#xff0c;黃博文 黃輝蘭 譯&#xff0c;更多章節內容可…

mysql語句數據庫_數據庫的Mysql語句

數據庫的mysql語句: 1.連接數據庫 mysql -u root -p2.顯示數據庫 show databases(db);3.選擇數據庫 use 數據庫名;4.顯示數據庫中的表 show tables;基本數據操作:增刪改查1.增 :insert into 表名(字段1,字段2…)values (值1,值2…);2.刪 :delete from 表名 where 條件;3.改 :up…

java clock計時_Java Clock類| systemUTC()方法與示例

java clock計時Clock Class systemUTC()方法 (Clock Class systemUTC() method) systemUTC() method is available in java.time package. systemUTC()方法在java.time包中可用。 systemUTC() method is used to get a Clock that implements the suitable system clock in the…

《Android 應用測試指南》——第2章,第2.4節包瀏覽器

本節書摘來自異步社區《Android 應用測試指南》一書中的第2章&#xff0c;第2.4節包瀏覽器&#xff0c;作者 【阿根廷】Diego Torres Milano&#xff08;迭戈 D.&#xff09;&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看 2.4 包瀏覽器創建完前面提到的兩個…

操作系統系統調用_操作系統中的系統調用

操作系統系統調用系統調用簡介 (Introduction to System calls) The interface between the operating system and the user program is defined by the set of extended instruction that the operating system provides. These extended instructions are known as system ca…

java分數表示_表示Java分數的最佳方法?

小編典典碰巧的是不久前我寫了一個BigFraction類&#xff0c;用于解決Euler項目問題。它保留了BigInteger分子和分母&#xff0c;因此它將永遠不會溢出。但是&#xff0c;對于許多你永遠不會溢出的操作來說&#xff0c;這會有點慢。無論如何&#xff0c;請根據需要使用它。我一…

《OpenStack云計算實戰手冊(第2版)》——1.7 添加用戶

本節書摘來自異步社區《OpenStack云計算實戰手冊&#xff08;第2版&#xff09;》一書中的第1章&#xff0c;第1.7節,作者&#xff1a; 【英】Kevin Jackson , 【美】Cody Bunch 更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 1.7 添加用戶 在OpenStack身份認證服務中…

開源軟件和自由軟件_自由和開源軟件的經濟學

開源軟件和自由軟件零邊際成本 (Zero Marginal Cost) At the core of the financial aspects of Free and Open Source is the zero negligible expense of merchandise in an environment that is digital. Right now, the rise of Free and Open Source speaks to an affirma…

java外部類_Java里什么叫內部類什么叫外部類

展開全部對普通類(沒有內部類的類)來說&#xff0c;62616964757a686964616fe78988e69d8331333337396234內部類和外部類都與他無關&#xff1b;對有內部類的類來說&#xff0c;它們就是其內部類的外部類&#xff0c;外部類是個相對的說法&#xff0c;其實就是有內部類的類。所以…

《精通Matlab數字圖像處理與識別》一6.2 傅立葉變換基礎知識

本節書摘來自異步社區《精通Matlab數字圖像處理與識別》一書中的第6章&#xff0c;第6.2節&#xff0c;作者 張錚 , 倪紅霞 , 苑春苗 , 楊立紅&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看 6.2 傅立葉變換基礎知識 精通Matlab數字圖像處理與識別要理解傅立…

多線程循環輸出abcc++_C ++循環| 查找輸出程序| 套裝5

多線程循環輸出abccProgram 1: 程序1&#xff1a; #include <iostream>using namespace std;int main(){int num 15673;int R1 0, R2 0;do {R1 num % 10;R2 R2 * 10 R1;num num / 10;} while (num > 0);cout << R2 << " ";return 0;}Ou…

java oql_深入理解java虛擬機(八):java內存分析工具-MAT和OQL

以下內容翻譯自MAT幫助文檔。一、Class HistogramClass Histogram shows the classes found in the snapshot, the number of objects for each class, the heap memory consumption of these objects, and the minimum retained size of the objects二、Dominator treeDomina…

《Python數據分析與挖掘實戰》一1.2 從餐飲服務到數據挖掘

本節書摘來自華章出版社《Python數據分析與挖掘實戰》一書中的第1章&#xff0c;第1.2節&#xff0c;作者 張良均 王路 譚立云 蘇劍林&#xff0c;更多章節內容可以訪問云棲社區“華章計算機”公眾號查看 1.2 從餐飲服務到數據挖掘 企業經營最大的目的就是盈利&#xff0c;而餐…

obj[]與obj._Ruby中帶有示例的Array.include?(obj)方法

obj[]與obj.Ruby Array.include&#xff1f;(obj)方法 (Ruby Array.include?(obj) Method) In the previous articles, we have seen how we can check whether two Array instances are identical or not with the help of <> operator, operator, and .eql? method?…

java javah_Java開發網 - 一個javah的問題

Posted by:jerry_xuPosted on:2006-03-13 15:39我在環境變量中已經設置了path為D:\Program Files\Java\jdk1.5.0_06&#xff0c;ClassPath設置為.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;class的路徑為&#xff1a;D:\JNItest\bin\jni\Hello.class &#xff0c;但是…