當(dāng)前位置:首頁(yè) > 芯聞號(hào) > 充電吧
[導(dǎo)讀]一:跨平臺(tái)APP開發(fā)目前采用html5+javascript+css 開發(fā)跨平臺(tái)應(yīng)用正成為一個(gè)熱點(diǎn)。html5開發(fā)網(wǎng)頁(yè)的骨架,CSS開發(fā)網(wǎng)頁(yè)皮膚,JS用于網(wǎng)頁(yè)互動(dòng)。即僅需維護(hù)一套代碼,通過不同編譯方式

一:跨平臺(tái)APP開發(fā)



目前采用html5+javascript+css 開發(fā)跨平臺(tái)應(yīng)用正成為一個(gè)熱點(diǎn)。html5開發(fā)網(wǎng)頁(yè)的骨架,CSS開發(fā)網(wǎng)頁(yè)皮膚,JS用于網(wǎng)頁(yè)互動(dòng)。即僅需維護(hù)一套代碼,通過不同編譯方式,適配PC端,ios移動(dòng)端,android移動(dòng)端。 在跨平臺(tái)框架中,meteor 以快速開發(fā)著稱。

二: Meteor 強(qiáng)大之處

1. 極速構(gòu)建

a. 幾條命令完成創(chuàng)建

b. 服務(wù)端客戶端一體(屏蔽通訊實(shí)現(xiàn))

c. 包含數(shù)據(jù)庫(kù)

2.Plugin插件 豐富

3.包容第三方(如react)

4.官方文檔完善

三:Meteor App 效果演示

meteor官網(wǎng)上有app 效果演示,如下面的截圖。功能強(qiáng)大。

四:用meteor 快速實(shí)現(xiàn) App

1. 創(chuàng)建

#curl https://install.meteor.com | /bin/sh 安裝meteor

#meteor create a1_hello

#cd a1_hello

#meteor 運(yùn)行

更改a1_hello.html 保存 網(wǎng)頁(yè)會(huì)同步變化

瀏覽器訪問http://localhost:3000會(huì)看到:

//----源碼a1_hello.html 實(shí)現(xiàn)界面的顯示






Welcome to Meteor!


{{> hello}} //調(diào)用模板hello


//定義模板hello (模塊對(duì)外的顯示)


Youve pressed the button {{counter}} times.

//{{counter} 調(diào)用模板hello里的對(duì)象counter




//----源碼a1_hello.js 實(shí)現(xiàn)界面的互動(dòng)

if (Meteor.isClient) { //檢測(cè)是否是客戶端,是則使用下面的代碼運(yùn)行

// counter starts at 0

Session.setDefault('counter', 0); //設(shè)置counter的鍵值為0 --- Session 用于處理 鍵值對(duì)(key-value)

Template.hello.helpers({ // 實(shí)現(xiàn)模板hello的 helpers方法

counter: function () { // 把對(duì)象counter和函數(shù)function 關(guān)聯(lián)起來 (接口+實(shí)現(xiàn))

return Session.get('counter'); //返回counter的鍵值

}

});

Template.hello.events({ // 實(shí)現(xiàn)模板hello的事件 click button

'click button': function () { //click button 是事件,function是事件觸發(fā)的函數(shù) (接口+實(shí)現(xiàn))

// increment the counter when button is clicked

Session.set('counter', Session.get('counter') + 1); //使counter值加一

}

});

}

if (Meteor.isServer) { //檢測(cè)是否是服務(wù)端,是則使用下面的代碼運(yùn)行

Meteor.startup(function () {

// code to run on server at startup

});

}

2. 列表顯示

//----源碼a1_hello.html 加入 列表顯示

List

{{> task}}

list 1

list 2

list 3

//----源碼 a1_hello.css 設(shè)置 顯示效果

body { //設(shè)置 html中自帶的body標(biāo)簽對(duì)象的 顯示屬性

font-family: sans-serif;

background-color: #315481;

background-image: linear-gradient(to bottom, #315481, #918e82 100%);

background-attachment: fixed;

position: absolute;

top: 0;

bottom: 0;

left: 0;

right: 0;

padding: 0;

margin: 0;

font-size: 14px;

}

.container { //設(shè)置自建的類名為container的對(duì)象的 顯示屬性

max-width: 600px;

margin: 0 auto;

min-height: 100%;

background: white;

}

header { //設(shè)置header對(duì)象的 顯示屬性

background: #d2edf4;

background-image: linear-gradient(to bottom, #d0edf5, #e1e5f0 100%);

padding: 20px 15px 15px 15px;

position: relative;

}

ul { //設(shè)置ul列表對(duì)象的 顯示屬性

margin: 0;

padding: 0;

background: white;

}

li { //設(shè)置li列表項(xiàng)對(duì)象的 顯示屬性

position: relative;

list-style: none;

padding: 15px;

border-bottom: #eee solid 1px;

}

3. 遠(yuǎn)程數(shù)據(jù)庫(kù)存儲(chǔ)

//----源碼a1_hello.html 使用表單輸入方式,添加列表內(nèi)容顯示











//----源碼a1_hello.js 表單輸入后能插入數(shù)據(jù)庫(kù)中(MongoDB Collection)


Tasks = new Mongo.Collection("tasks"); //創(chuàng)建數(shù)據(jù)庫(kù)連接(MongoDB collection) “tasks" 用于存儲(chǔ)列表內(nèi)容


if (Meteor.isClient) {


// This code only runs on the client


Template.body.helpers({


tasks: function () {


return Tasks.find({},{sort: {createdAt: -1}}); //查找數(shù)據(jù)庫(kù)MongoDB內(nèi)容并排序, 詳見API文檔 http://docs.meteor.com/#/basic/Mongo-Collection-find


}


});


Template.body.events({


"submit .new-task": function (event) { //實(shí)現(xiàn)對(duì)象new-task的submit事件的觸發(fā)函數(shù)


// Prevent default browser form submit


event.preventDefault();


// Get value from form element


var text = event.target.text.value;


// Insert a task into the collection


Tasks.insert({


text: text,


createdAt: new Date() // current time


});


// Clear form


event.target.text.value = "";


}


});


}


if (Meteor.isServer) {


Meteor.startup(function () {


// code to run on server at startup


});


}


五:豐富組件


搜索組件 https://atmospherejs.com


使用account組件


?#meteor add accounts-ui


#meteor add accounts-password



六:開源的樣例

#meteor create --example todos

#cd todos

#meteor

瀏覽器訪問http://localhost:3000會(huì)看到

#meteor create --example localmarket

#cd localmarket

#meteor


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

倫敦2024年8月29日 /美通社/ -- 英國(guó)汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對(duì)日本游戲市場(chǎng)的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開幕式在貴陽(yáng)舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語(yǔ)權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對(duì)環(huán)境變化,經(jīng)營(yíng)業(yè)績(jī)穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤(rùn)率延續(xù)升勢(shì) 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長(zhǎng) 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競(jìng)爭(zhēng)力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競(jìng)爭(zhēng)優(yōu)勢(shì)...

關(guān)鍵字: 通信 BSP 電信運(yùn)營(yíng)商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國(guó)電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場(chǎng) NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長(zhǎng)三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡(jiǎn)稱"軟通動(dòng)力")與長(zhǎng)三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉