uml.org.cn - VUE.JS??????????ʵ??









Search Preview

VUE.JS组件化开发实践

uml.org.cn
body { margin: 0px;padding:0 } #div1 { display: none; position: absolute; z-index: 1000; height: 100%; width: 100%; backgrou
.cn > uml.org.cn

SEO audit: Content analysis

Language Error! No language localisation is found.
Title VUE.JS组件化开发实践
Text / HTML ratio 67 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud
Keywords consistency
Keyword Content Title Description Headings
Headings Error! The website does not use (H) tags.
Images We found 64 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density

SEO Keywords (Two Word)

Keyword Occurrence Density

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam

Internal links in - uml.org.cn

????
文章-火龙果软件工程
iProcess
iProcess--火龙果软件工程技术中心
?ֲ?ʽϵͳ?еĻ????ܹ?
一文深入了解:分布式系统中的缓存架构-数据库
BitbucketPipeline+AmazonS3
基于 Bitbucket Pipeline + Amazon S3 的自动化运维体系-IT运维管理
΢??΢???????ؿ???ϵͳ
DAGOR:微信微服务过载控制系统-移动端开发
???ݿ?
数据库-火龙果软件工程
IT??ά????
IT运维管理-火龙果软件工程
΢????
微服务-火龙果软件工程
????vuex??״̬????ģʽ?ܹ?
理解vuex的状态管理模式架构
TensorFlow??????????NLP
运用TensorFlow处理简单的NLP问题-人工智能-火龙果软件
web????
JavaScript-火龙果软件工程
?˹?????
人工智能-火龙果软件工程
????TensorFlow?ڲ?ʵ??ԭ??
从系统和代码实现角度解析TensorFlow的内部实现原理-人工智能-火龙果软件
ʹ??IPython??ǿ????ʽ????
使用IPython增强交互式体验-Python
?????Ͳ?????????????Ӧ??
在 IBM Cloud 上创建和部署区块链聊天应用
python
python-火龙果软件工程
?Ƽ???
云计算-火龙果软件工程
VUE.JS??????????ʵ??
VUE.JS组件化开发实践
???????ɵ?·????C++???߳̿???
瑞萨C++多线程开发培训-火龙果软件
?й????Ų?Ʒ????
产品经理产品管理培训| 产品经理培训
ծȯ???ۻ??? ʹ??Selenium?????Զ???
使用Selenium进行有效的自动化测试-火龙果软件-UML软件工程组织
????֤ȯ?߿????ƶ???̨?ܹ?????
高可用架构培训|软件架构培训-火龙果软件
E2Biz ????UML+EA ҵ????ϵͳ??ģ
基于UML+EA进行嵌入式系统分析设计培训-火龙果软件-UML软件工程组织
???Ź???????????ѵ
工作量估算管理培训-火龙果软件
????
培训案例-火龙果软件
??ΰ?? ͨ????????֤???????ܹ?ʦ
软件架构师认证|软件架构师培训-火龙果软件
???? ͨ????????֤???????ܹ?ʦ
软件架构师认证|软件架构师培训-火龙果软件
??ѧ?? ͨ????????֤???????ܹ?ʦ
软件架构师认证|软件架构培训-火龙果软件
???? ͨ????????֤???????ܹ?ʦ
软件架构师认证|软件架构师培训-火龙果软件
Githubʹ?ÿ???????
Github使用快速上手-配置管理
?? Vuex ????һ???ʼ?Ӧ??
用 Vuex 构建一个笔记应用 -web开发
???ù???
配置管理-火龙果软件工程
????matplotlib?????ݿ??ӻ?
基于matplotlib的数据可视化 -Python
OnlineLearning?㷨??????ʵ??
Online Learning算法理论与实践-火龙果软件
????
每月技术月刊--UML软件工程组织
????????
火龙果软件工程技术中心
??ϵ????
联系我们-UML软件工程组织

Uml.org.cn Spined HTML


VUE.JSʵ Ծ֧ǵĹҵ 1Ԫ 10Ԫ 50Ԫ ֤룺     ֪ Ŀ Lib Ƶ Code iProcess γ ֤ ѯ   ɳ֮·   Ա          Ҫ      ÿ15ƪ ı ׷                 VUE.JSʵ   69     ۣ     2018-9-25   ༭Ƽ: Ը˲ͣͨVue APIݣdzES6Vueصݺmvvm˼롣 ǰ ˾ĿǰһH5رһͳһṹĻҪһظӡӵһģĻϵͳ󣬱һµݡȻʹVueпһЩǰҪļм򵥽ܡ һӾôʵ֣ѡȻΪ˵һ⡣ĿǰwebǰmvvmԼʽУջãvue + vuex + es6 + browserify ȼ˵webǰʽ̣ ṹṹ£ - lib/components/calendar |- calendar.css |- calendar.js |- calendar.html ͬܵļŵͬһĿ¼£ṹְȷͼʽűĹϵҲڵԪԣǶչʾͽСԪ ֮ǰ϶ڵļӹ(ʼȡԴȾ¡ٵ)˳ĸ׶Σڶʵ(ӳʼ)⡣ҽ׶εĹӿԶиõúչⱩ¶ӿڣݰ󶨻˵ݲֿļ룬xMDģij֣Ҳֿʽһ㼶ExtJsYUIȶⷽרҡ ٺ ֮ǰչǺܴģȻĿɸ(ʽ߼ԡɸõȶҵ߼)ͨšȫ״̬ܷиõĴ֯ʽȻ⡣AngularReactPolymerVuemvvmܺwebpackbrowserifyȹԤ빤ߵijͼЩ⡣ ES6 ʽʼvue֮ǰΪĿões6ô̸̸ҶעEcmaScript6ľͲ˵ˣes6˶Ŀ࣬2015°궨壬ʽƣEcmaScript2015ÿտʼӴes6Ӧöôһ⣬es6ijֵΪʲô˵ʲôϰ汾es4/5ȻӶ࣬Brendan Eichjsһ"֮ԭԭ֮"DzҲȥɣ侫裬һ·߹ ֱһ㣬es6õУclass֧֡ͷĽ⹹Ĭϲϲletconstؼ֡for ofַģ塢ǿͬдģ黯import/exportmappromise* yeildȡ õļ˵£ class: ûclassʱ򣬴һֱȽϱ׼ķʽǽǺԷŵ캯ԭӡļ̳еʵ־͸Ϊð䡢call/applyʽԭʽȡes6classextendsؼֵijָһͳһĹ淶 matriculation People { constructor (name, age, gender){ this.name = name } sayName (){ return this.name } } matriculation Student extends People { constructor (name, age, gender, skill){ super(name, age, gender) this.skill = skill } saySkill (){ return this.skill } } let tom = new Student('tom', 16, 'male', 'computer') tom.sayName() // => 'tom' tom.saySkill() // => 'computer' tom.__proto__ == Student.prototype // => true Student.__proto__ == People // => true ԿȻµĹ淶ǻjsԭ򣺶__proto__ָĹ캯()prototypees6__proto__עҲܿٵʵּ̳С ڴVueУDzԼдclassΪVueǸ߶ȷװģֻҪײclassǵö󼴿ɣ˽es6classҲбҪġVuereact˵һͬĵط let es6֮ǰjsֻкletij˿鼶ҲifelseforҲ򣬿letıǷʲģjsԤʱDzᱻǰǰġڸԣforʱÿεһ鼶ĶĵĽڴĽ var arr = []; for (let i = 0; i < 10; i ++){ arr[i] = function (){ return i } } arr[6]() // => 6 //vari۶ٴεiʼձÿεĺڲ(հ)ᱻգĽָͬһiֵΪ10 //Ϊ˱⣬ͨô for (var i = 0; i < 10; i ++){ arr[i] = (function (i){ return function (){ return i } })(i) } 󽲽ͷ es6֮ǰfunctionһص㣺ڲIJɸúдģ˭þģ˭úڲthisָ˭ȻЩʱ򲢲û취ֻͨȱthiscall/applybindġͷijֽ˿յ⣬Ϊͷڵ(this)ɺдľģ۱ĸãĶı䡣 // window var obj = { test1 : function (){ window.setTimeout(function (){ console.info(this) }, 100) }, test2 : function (){ window.setTimeout(() => { console.info(this) }, 100) }, test3: () => console.info(this), test4: function (){ console.info(this) }, test5 (){ // ǿд console.info(this); } } obj.test1() // => Window {} obj.test2() // => obj {} obj.test3() // => Window {} obj.test4() // => obj {} obj.test5() // => obj {} ͷthisֵϸϸƷζĿǰVueReactӦá ͨǼͷǾԣͷҲȫͨҪĸɾ߼ǰҪ˽ǵ ͷһصܹreturnд var a = function (n){ return n } var b = (n) => n //ʡreturnͻ var c = n => n //ֻһҲʡ a(1) // => 1 b(1) // => 1 c(1) // => 1 ⼸򵥵ӿԿes6˼ǣ֮ǰjsһЩѺõĵطĸƲص㡣 Vue ⣬ Vue.js /vju?/, viewһ web Ŀ⡣Vue.js Ŀܼͨ򵥵 API ʵӦݰ󶨺ϵͼ Vue.js һȫܿܡֻ۽ͼ㡣dzѧϰdzĿϡһ棬عߺֿ֧һʹʱVue.js ҲӵĵҳӦá йvueĴ󲿷vueĹٷĵлߵĹ Ӧݰ󶨣 <div id="app"> <p>{{ message }}</p> <input v-model="message"> </div> new Vue({ el : '#app', data : { message : 'Hello Vue.js!' } }) ıֵ<p>ǩıҲӦı䡣 ԭ<input>ֵvueʵmessageԽ˰󶨣<p>ǩıҲmessageԽ˰󶨡ֵı仯ımessageֵmessageֵı仯ᷴӦ<p>ǩıϡ Vue.js ĺһӦݰϵͳ DOM ͬdz򵥡ʹ jQuery ֹ DOM ʱǵĴ볣ʽġظ״ġVue.js ӵͼͨ׵ؽζͨ HTML ģʹ﷨ DOM 󶨡ײݡһ˰󶨣DOM ݱͬÿ޸ݣDOM Ӧظ¡Ӧе߼ͼֱ޸ˣ DOM ½һǵĴ׫дά ϵͳ ϵͳ Vue.js һҪΪṩһֳǿöɸõСӦáǿǵ㣬͵ӦõĽ涼ԳΪһ ʵϣһ͵ Vue.js ĴӦýγһ Ѿע⵽ Vue.js dzԶԪء Web 淶һ֡ʵ Vue.js ﷨ο˸ù淶 Vue ʵ Slot API is ԡǣмؼIJͬ Web 淶ȻԶδɣûʵ֮֡£Vue.js Ҫκβֵ֧IE9 ߰汾֮±һ¡ҪʱVue.js ҲԷԭԶԪ֮ڡ Vue.js ṩԭԶԪ߱һЩҪܣԶ¼ϵͳԼ̬ġЧ滻 ϵͳ Vue.js ӦõĻ⣬Vue.js ̬ϵͳҲṩ˸߼ֿ֧⣬Ǻ Vue.js һ𹹳һӡܡԵϵͳ 򵥽vueҲҪ飺Ӧʽԭϵͳ Ӧʽԭ Vue.jsݹ۲ʵԭAngularűʵIJͬ˽AngularĶ߿֪Angularݹ۲õ飨dirty checkingơÿһָһӦ۲ݵĶ󣬽watcherһлкܶwatcherÿҪʱAngularǰwatcherһһֵȻ֮ǰľֵбȽϡֵĽ仯ˣʹӦĸ£̽digest cycle ⣺ 1.κݱ䶯ζŵǰÿһwatcherҪֵ˵watcherӴʱӦõܾͲɱܵӰ죬ҺŻ 2.ݱ䶯ʱܲ⵽仯ķҪֶdigest cycleܴӦDOM ¡AngularͨDOM¼Զdigest cycleֹ⣬кܶҪûֶд Vue.jsõǻռĹ۲ơԭ˵MVVMKnockoutһġռĻԭǣ 1.ԭݸ ɹ۲󡱡һɹ۲ԱȡֵҲԱֵ 2.watcherֵУÿһȡֵĿɹ۲󶼻ὫǰwatcherעΪԼһߣΪǰwatcherһ 3.һĿɹ۲󱻸ֵʱ֪ͨжԼwatcherֵӦĸ¡ 4.ռŵڿԾȷ׷ݵı仯ᵽ⡣ͳռʵ֣KnockoutͨҪԭɹ۲ȡֵ͸ֵʱҪúõʽڽݲʱдֱۣͬʱԸǶ׽ṹĶ֧Ҳ롣 Vue.jsES5Object.definePropertyֱӽԭݶԸΪgettersetter(ES5ԣҪjs֧֣޷ִͨshimʵ֣ڵbabel pollyfill͸shimûġҲΪʲôVue֧IE8°汾ԭΪIE8definePropertyֻ֧DOM󣬴Objectᱨ)ڲʵռʹ֧Ƕ׵Ķṹ飬ͨĿɱ䷽pushı仯ʹòVue.jsݺͲԭ󼸺ûв[ע:/ɾԣ޸ضλԪʱҪضĺobj.$add(key, value)ܴ¡ES5ޡڲݵʱһҪע㣬޷ʵӦ 仯⣺ ES5 ƣVue.js ܼ⵽ԵӻɾΪ Vue.js ڳʼʵʱתΪ getter/setterԱ data ϲ Vue.js תӦġ磺 var data = {a : 1} var vm = new Vue({ data : data }) //vm.a data.a Ӧ vm.b = 2 //vm.b Ӧ data.b = 2 //data.b Ӧ а취ʵ֮ԲӦġ Vue ʵʹ $set(key, value) ʵ vm.$set('b', 2) //vm.b data.b Ӧ ͨݶ󣬿ʹȫַ Vue.set(object, key, value) Vue.set(data, 'c', 3) //vm.c data.c Ӧ ʱжһЩԣʹ Object.assign() _.extend() ԡǣӵϵԲᴥ¡ʱԴһµĶ󣬰ԭԺµԣ // ʹ Object.assign(this.someObject, {a : 1,b : 2}) this.someObject = Object.assign({}, this.someObject, {a : 1, b : 2}) Եİأ Ӧע⵽ Vue.js ļԲǼ򵥵 getterԳ׷ӦڼһʱVue.js бֻеһ˱仯ĽЧˣֻҪ仯ʼԻֱӷػĽǵ getter ΪʲôҪأһߺļ AҪһ鲢ļ㡣Ȼ󣬿ļ Aûл棬ǽ A getter ΣҪ ڼԱˣڷʱ getter DZá var vm = new Vue({ data : { msg : 'hi' }, computed : { example : function (){ return Date.now() + this.msg } } }) example ֻһ vm.msg Date.now() ӦΪ Vue ݹ۲ϵͳ޹ءڷ vm.example ʱʱ䣬 vm.msg ˡ ʱϣ getter ıԭеΪÿη vm.example ʱ getterʱΪָļԹرջ棺 computed : { example : { enshroud : false, get : function (){ return Date.now() + this.msg } } } ÿη vm.example ʱʱµġǣֻ JavaScript зģݰġģ󶨼 {{example}} ֻӦ仯ʱŸDOM ϵͳ Component Vue.js ǿĹ֮һչ HTML ԪأװõĴ롣ڽϸ߲ϣԶԪأVue.js ıΪ⹦ܡЩ£Ҳԭ HTML Ԫصʽ is չ 1.ע Vue.extend() һ var MyComponent = Vue.extend({ template : '<div>A custom component!</div>' }) ҪҪ Vue.component(tag, constructor) ע(עȫֵ) //ȫעtag Ϊ my-component Vue.component('my-component', MyComponent) ע֮󣬱ڸʵģԶԪ <my-component> ʽʹáҪȷڳʼʵ֮ǰע <div id="example"> <my-component></my-component> </div> ȾΪ <div id="example"> <div>A custom component!</div> </div> Ȼֻڣʵѡ components עᣬ磺 var Child = Vue.extend({ /* ... */ }) var Parent = Vue.extend({ template : '...', components : { // <my-component> ֻڸģ 'my-component': Child } }) ־ֲעķʽҲԴָ͹ɡǶ֧ȫֺ;ֲעᡣ ǰᵽǿԱõģʵܻṲһôעһѡ⣺ Vue ĶѡҲ Vue.extend() У data elǼ򵥵ذһΪ data ѡ Vue.extend() var data = {a : 1} var MyComponent = Vue.extend({ data : data }) ô MyComponent еʵͬһ data ΪôݵģҪģӦʹһΪ data ѡһ¶ var MyComponent = Vue.extend({ data : function (){ return {a : 1} } }) ͬel ѡ Vue.extend() ʱҲһ 2.ʹprops һڲһʱʵǹģζŲܲҲӦģֱøݡʱʹpropsݴ prop ݵһֶΣӸҪʽ props ѡ props Vue.component('child', { //camelCase in JavaScript props : ['myMessage'], template : '<span>{{ myMessage }}</span>' }) Ȼһַͨ <child my-message="hello!"></child> Ⱦ ϰߣעcamelCasekebab-caseHTML ԲִСдʽΪ camelCase prop ʱҪתΪ kebab-case(̺߸) vueӦԣpropsҲǶ̬ģ v-bind HTML ԵһʽҲ v-bind 󶨶̬ Props ݡÿݱ仯ʱҲᴫ <div> <input v-model="parentMsg"> <br/> <child v-bind:my-message="parentMsg"></child> </div> Ҳʹv-bindд﷨򻯰󶨣 <child :my-message="parentMsg"></child> Ⱦ ıֵıŸı propsܣο props 3.ͨ this.$parent ĸʵĺ this.$root һ this.$children еԪء ܿԷʸʵӦֱݣʽʹ props ݡ⣬޸ĸ״̬ǷdzΪ øܵϣ ֻ⸸״̬Ϊܱ޸ģ£ֻԼ޸״̬ Vue ʵʵһԶ¼ӿڣͨš¼ϵͳԭ DOM ¼÷Ҳͬ ÿ Vue ʵһ¼ ʹ $on() ¼ ʹ $emit() 津¼ ʹ $dispatch() ɷ¼¼Ÿðݣ ʹ $broadcast() 㲥¼¼´еĺ ͬ DOM ¼Vue ¼ðݹеһδص֮Զֹͣðݣǻصȷ true һ򵥵ӣ <!-- ģ --> <template id="child-template"> <input v-model="msg"> <button v-on:click="notify">Dispatch Event</button> </template> <!-- ģ --> <div id="events-example"> <p>Messages: {{ messages | json }}</p> <child></child> </div> ֵԺ󣬵ťMessages:[]ıӦ仯 4.˵˵̬ ʹͬһص㣬Ȼ̬֮лʹñ <component> Ԫأ̬ذ󶨵 is ԣ new Vue({ el : 'body', data : { currentView : 'home' }, components : { home : { /* ... */ }, posts : { /* ... */ }, gazetteer : { /* ... */ } } }) <component :is="currentView"> <!-- vm.currentview 仯ʱı --> </component> лȥڴУԱ״̬ȾΪ˿һ keep-alive ָ <component :is="currentView" keep-alive> <!-- ǻ --> </component> ̬ϸܣο̬ ڴӦõʱ򣬶̬Եòôˣʱʹ·ɣvue-router·չԿǶ̬棬ɲοvue-router 5.ʵڣ Vue ʵڴʱһϵгʼ衪磬Ҫݹ۲죬ģ壬Ҫݰ󶨡ڴ˹УҲһЩڹӣԶ߼ṩлᡣ created ʵã var vm = new Vue({ data : { a : 1 }, created : function (){ // this ָ vm ʵ console.log('a is: ' + this.a) } }) // => "a is: 1" ҲһЩĹӣʵڵIJͬ׶εã compiled ready destroyedӵ this ָ Vue ʵһЩûܻ Vue.js ǷСĸǣûСԶ߼ԷָЩС ڵͼʾ ļ򵥽ܾ͵ Vuex ڴӦУ״̬øӣΪ״̬ɢڣڲͬڡvue˵ʹvue-routerԼ(.vue)͵ҳӦõʱ֮״̬ݵĴݻѣȻpropsdispatchbroadcastܹпݴݣǴʹǻʹ֮ϳ̶ȺܸߣԽ࣬㼶Խ࣬άԽӡôأܷȫṩһ״̬ܣ һFlux FluxFacebookû˵webӦõӦóϵܹͨݵĵΪReactĿɸõͼṩ˲䡣ʽĿһܹ˼룬Ҫ̫µĴͿʹFluxӦá FluxӦҪ֣dispatcherstoreviewsReact componentsǧҪMVC(model-View-Controller)졣ControllerFluxӦҲȷʵڣcontroller-viewʽviewͨӦõĶ㣬storesлȡݣͬʱЩݴݸĺڵ㡣⣬action creators - dispatcher - һṩӦпܴڵĸı廯APIΪFlux±ջĵĸɲֿ԰õ һ仰FluxֶActionײͼе¼ֶ󶨵ݶܹ ĿģκUIֱӶдǷֹͬһжطͬʱдֱӽ˫󶨣΢Ḵһ㣬Ŵάıݡ Flux ܹ React ӦУĺҲ Vue.js Ӧá Vuex һ FluxרΪ Vue.js Ƶ״̬React ̬Ȧе Flux ʵ Redux Ҳͨ򵥵İ󶨺 Vue һʹá ʲôVuex Vuex һרΪ Vue.js ӦƵļʽ״̬ܹ Flux Redux ˼룬˸ҲһΪܸ÷ Vue.js ӦƶרƵʵ֡ ΪʲôҪ Ӧûܼ򵥵ʱ벢Ҫ VuexҲʹ VuexڹһϹģ SPAпѾҪ˼Ӧθõع Vue ֮⣬Ӧõɲ֡ Vuex Ҫֵʱ̡ ڵʹ Vue.js ʱͨ״̬ڲҲ˵ÿһӵеǰӦ״̬һ֣Ӧõ״̬ǷɢڸġȻǾҪ״̬һֹһĽΪʹöƵ¼ϵͳһһЩ״̬͡Сģʽڣе¼ܿ÷dzӣҵʱȥҳĴˡ Ϊ˸õĽڴӦ״̬Ĺ⣬Ҫ ״̬(component local state) Ӧò㼶״̬(application level state) ֡Ӧü״̬κضÿһȻԼ(Observe)仯ӶӦʽظ DOMͨӦõ״̬һǾͲص¼Ϊκǣһ߼Ӧд⣬ҲǸ׵ؼ¼۲״̬ıMutationԭΪͻ䣩ʵֳʱһĵЧעʱһ vue-devtools ˣ Vuex Ҳιص״̬һЩԼԱ㹻ʵʹóԡ һҪ VuexôôⲢһҪĿʹǵĿһƽ̨ϵͳһ޷бתִ䣬ͬбҳ桢ͬҳ֮ûʲô໥Ҫ״̬ҲijһҪȡҳ״̬ʱDzҪVuexģʹֻĿĸӶȡ潫ܵĻϵͳ󴴽ʱҪȡݣʱʹVuexԵʮбҪ㶼֪ǷҪVuexǾͲ 򵥵store Vuex store Ĺ൱ֱ˵ - ֻҪṩһʼ state ԼһЩ mutations import Vuex from 'vuex' const state = { count : 0 } const mutations = { INCREMENT (state){ state.count ++ } } export default new Vuex.Store({ state, mutations }) ڣͨ store.state ȡ state 󣬻ͨ stimulation ij mutation Щ״̬ store.dispatch('INCREMENT') console.log(store.state.count) // -> 1 ڶķַʽ﷨ // Чͬ store.dispatch({ type : 'INCREMENT' }) ٴǿַͨ mutation ķʽֱӸı store.state ΪҪȷ׷ٵ״̬ı仯򵥵ԼܹͼԣĶʱܸ׵ؽӦڲ״̬ı䡣⣬ҲлȥʵһЩܼ¼ÿ״̬ı䣬״̬յĵԹߡʵʱ䴩ĵ顣 Vuex ʹ һ״̬ ǵģһͰȫӦò㼶״̬ΪһΨһԴ(SSOT)ڡҲζţÿӦýһ store ʵ״ֱ̬ܹӵضλһض״̬ƬΣڵԵĹҲ׵ȡǰӦ״̬Ŀա ֻһչʾ store ʲôһӡ̸̸ĸState״̬Mutations Actions StateGetters 1.װ Vuex ҽĸ store ʵ import Vue from 'vue' import Vuex from 'vuex' import store from './store' import MyComponent from './MyComponent' // ؼ㣬 Vue δ Vuex صѡ Vue.use(Vuex) var app = new Vue({ el : '#app', store, // store ṩ store ѡ԰ store ʵעе components : { MyComponent } }) ͨڸʵע store ѡ store ʵע뵽µУͨ this.$store ʵʵϣǼҪֱ 2.Уͨ vuex.getters ѡﶨ getter ȡ״̬ // MyComponent.js export default { template : '...', data (){ ... }, // ˴ΪǴ store ʵȡ״̬λ vuex : { getters : { // getter Ѳֿ `store.state.count` Ϊ `this.count` count : (state) => state.count } } } vuex ѡעgetters Ӷ󣩡ָǰܴ store ȡЩ״̬ϢĵطÿӦһ getter ú store ״̬ΪΨһ֮ȿԷ״̬һ֣ҲԷش״̬ȡļֵؽ getter ӵϣ÷ļһëһ ֱ޸storeʵ״̬ ʼռǵ÷dzҪ㣬ǣԶӦֱӸı Vuex store ״̬ΪҪ״̬ÿθı䶼ȷҿ׷٣Vuex ״̬иı䶼 store mutation handler () йΪǿùڿ(ϸģʽ(Strict Mode))ʱ store ״̬ mutation ⱻ޸ģVuex ͻᱨһ Vue ְܾ˺ֻࣺܶͨ getter Vuex store ״̬󶨣ΨһӰȫ״̬ķ취 mutationsǽ̸бҪȻܹͲ״̬Dzڵзκȫ״̬߼Щȫ Vuex صļУôӦñøά Mutation Mutations һ¼ϵͳÿ mutation һ ¼ (name) һ ص (handler). κһ Mutation handler ĵһԶΪ store state import Vuex from 'vuex' const store = new Vuex.Store({ state : { count : 1 }, mutations : { INCREMENT (state){ // ı state state.count ++ } } }) ȫд mutation һ㽫 deportment ֿ 㲻ֱӵ mutation handler. ﴫ Store 캯ѡע¼صINCREMENT ¼ʱ handler mutation handler ķ stimulation һ mutation ¼ store.dispatch('INCREMENT') Mutationͬ Ϊ mutation ʱ򣬻صûбãDz֪ʲôʱصʵϱáκڻصнеĵ״̬ĸı䶼Dz׷ٵġ MutationVueӦϵͳ 1.ڴ store ʱͳʼ state Ҫԡ 2.һԭڵʱҪʹ Vue.set(obj, 'newProp', 123) ߿滻ԭĶ stage 2 object spread syntaxǿʹ﷨: state.obj = {...state.obj, newProp : 123}DeportmentActions ڷַ mutations ĺչVuex deportment ĵһ store ʵϿѡԶ // 򵥵 whoopee function increment (store){ store.dispatch('INCREMENT') } // Ӳ whoopee // ʹ ES2015 ⹹ function incrementBy ({dispatch}, amount){ dispatch('INCREMENT', amount) } էһۿȥоһ٣ֱӷַ mutations 񲻸㣿ʵϲˣǵ mutations ִͬôActions ͲԼǿ whoopee ڲִ첽ִһajaxݵIJ function getData ({dispatch}){ ajax ({ url : "...", data : {...}, success : (data) => { dispatch("SET_DATA", data) } }) } ǿеactions // ijڲ // actions import {incrementBy} from './actions' const vm = new Vue({ vuex : { getters : { ... }, // state getters deportment : { incrementBy } } }) ľǰԭ incrementBy whoopee 󶨵 store ʵУ¶һ vm.increamentBy ʵдݸ vm.increamentBy IJ store Ȼһ𴫵ݸԭ whoopee Ե vm.incrementBy(1) ȼ incrementBy(vm.$store, 1) ȻдһЩ룬ģе whoopee ʡˣ <button v-on:click="incrementBy(1)">increment by one</button> ͨڴ App Уaction ӦðͬĿĽ / ģ黯 ĹοDeportment̸̸һҪĶ Ϊ˸õ Vuex app еһ򵥵ļ appע⣺ӽΪ˸õؽ͸ʵвҪּ򵥵ijʹ Vuex. // store.js import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) // Ӧóʼ״̬ const state = { count : 0 } // mutations const mutations = { INCREMENT (state){ state.count ++ }, DECREMENT (state){ state.count -- } } // store ʵ export default new Vuex.Store({ state, mutations }) // actions.js export const increment = ({ stimulation }) => dispatch('INCREMENT') export const decrement = ({ stimulation }) => dispatch('DECREMENT') <!- temmplate --> <div> Clicked: {{ count }} times <button v-on:click="increment">+</button> <button v-on:click="decrement">-</button> </div> // Ҫڸע store ʵһμ import store from './store' import {increment, decrement} from './actions' const app = new Vue({ el : '#app', store, vuex : { getters: { count: state => state.count }, actions: { increment, decrement } } }) ע⵽dz򵥣Ľǰ󶨵 stateȻûʱ actions ҲᷢӦõǵģ Flux 1.ûе whoopee á 2.Actions ַͨ mutations ޸ store ʵ״̬ 3.Store ʵ״̬仯ͨ getters ֪ Vuex ǿҪе״̬ Vuex store Щ״̬òûҪ仯׷٣ôȫ԰ Vuex (Ϊı״̬)繫ĽӿڣͨpropsݸΪЧ VuexοVuex vue-devtools vue-devtoolschromeһvuechrome̵crxչаװṩComponentsVuexԤ(state仯ٵ)ܣڿ͵ԡ Կpropԡԡvue getterԵȣԼVuexеĴmutationstate ǰֵǿܹעݶֱ۵չʾ˳ Vueģ黯 ڴĿΪ˸õعʹģ鹹ϵͳdzҪƼʹ CommonJS ES6 ģ飬Ȼʹ Webpack Browserify Webpack Browserify ֻģ߶ṩԴת APIͨԤתԴ롣磬 babel-loader babelify ʹ ES2015/2016 ﷨ ʹ Webpack + vue-loader Browserify + vueify Щļ Vue ѡֹȡľWebpack Ĺܸǿָ̬Դģ飬ȡ CSS һļȣԸһ㡣㲻Ҫ Webpack Щܣʹ Browserify 򵥣ĹʽʹùٷƷĽּܹ vue-cliοvue-cli ģϵͳ ϵͳֻǶԻģҪչʾݽƣʽͽɻh5ҳӾͽᡣÿһԳΪһh5չʾõÿ϶Ӧʽͽ߼վγһh5ҳ档 ÿһӦģʽ 1.ǩͨ϶Ӧ͵ 2.Ԥչʾǰ 3.༭༭ǰѡеĸ ɺģһ򵥵ĽڱΪ ͼʾЩıǩҪǩԤ󣬻ɶӦԤͱ༭Ԥ༭ʾӦı༭ڱ༭пԶб༭༭ɺͨȵݰ󶨣ԤӦͻͼʾǰݡ Ͼϵͳһŷ̸̸ʵ֡ ȣӱǩʼ ǩÿĿˣҲ˵ÿһǩһʶһǾȸָ type ڱ type 'sectionTitle' ͶƱ type 'vote' type 'content' û type 'user' ͼƬ type 'image' Ƶ type 'video' Ƶ type 'audio' ת type 'link' Ȼÿ϶һǩԤٸݸñǩtypeɶӦԤͱ༭Ԥͱ༭Ҫȷ޷ǾЩ༭Щ༭ʲôݡԽڱΪֻһ༭ڱıҲ˵ڱԤʾڱı༭ҪһıԽڱıб༭ģȰ󶨺öӦݣıݱ仯ᷴӦԤDOMϡ Ҫһ()ʹһ顣 ҸϲһǶԭvueĻ(pushspliceshift)˷װͨЩıݣӦġڱӦ£ıҪ鷳ЩرǸӵǶ׶ʹöͨidֱƥ䵽ӦݣͨҪһ¡es6for of뻹Ǻܼ򵥣ҲڲDOMӰ첻 //widgetData.js [ {id : "100",type : "vote", ...}, //ͶƱ {id : "101",type : "image", ...}, //ͼƬ {id : "102",type : "video", ...}, //Ƶ ] ÿݶidΨһģǩʱɵģidǹԤӦ༭ĹؼͨҵÿԤӦı༭ΪʲôͨtypeжأΪÿжͬڱ⡣ͨtypeûȷӦϵ ͨVuexһstore洢޸(ٷ˵ǹstate״̬)ᵽVuexUIֱ޸ݡڱ༭ıijֱֵӸı˶ӦһֵͨDOM¼ӦactionactionɷӦmutaion޸stateַʽȷжijݵ޸Ķͨijһactionɵģactionǽij޸ĵͳһΨһڡ ֪ҪʲôԤͱ༭ʱ򣬲ŽʱǾͱ֪Щ༭(⣬ǷݶҪЩ)ʱǾҪһmaptype༭ĹϵԻͶƱΪ ͶƱҪ±༭ 1.ͶƱı 2.ͶƱÿҪһƣÿܻ(ȷѡıǵ) //typeDataMap.js export default { vote : { type : "vote", title : "ͶƱı", items : [ {name : "ͶƱ1"}, //ÿͶƱ {name : "ͶƱ2"}, {name : "ͶƱ3"} ] } } ֻҪ֪ʲôͣͨ typeData[type] ܻȡݲˡԤͱ༭ģͼȶDOMݰ󶨣Ǹıijʱ¾ͻᷴӦDOMϡDZģʱֻҪȡеֵˣʵҲǸ鱾H5չʾͨ飬õԼ򣬰նõģȾɡȻͶƱнݵϵͳƵģֻȷҪչʾĹ̶ݡͶƱÿͶƱҪ˴뵽Ӧ棬չʾʾ ϵͳŵ˼ģЩ ǩ Ϊǩıֺͽ߼ȶһµģһɸõıǩtitle(ǩı)type(ǩ)ڱǩһбǩݶ飬ģͼб飬ʹеıǩ ǩͳһԺͷȴһ棬ԺͨmixinʽϣͻӵЩԺͷĿǰ岻ΪѾһıǩˣmixinĶȫֱдڡÿ͵ıǩһ.vueļmixinĺôֳˣɸáά ʵֵĴ룬ʡԵʽ //labelWrapper.vue ǩ(ǩ) <template> <div class="label-wrapper"> <div class="label-title">ǩ</div> <div class="label-box"> <common-label v-for="label in labelArr" :title="label.title" :type="label.type"></common-label> </div> </div> </template> <script> import commonLabel from './widget/commonLabel.vue' //빫ǩ export default { name : "label_wrapper", components : { commonLabel //עΪ(es6ͬд) }, data (){ return { labelArr : [ {title : "ڱ", type : "sectionTitle"}, {title : "ͶƱ", type : "vote"}, {title : "", type : "content"}, {title : "û", type : "user"}, {title : "ͼƬ", type : "image"}, {title : "Ƶ", type : "video"}, {title : "Ƶ", type : "audio"}, {title : "ת", type : "link"} ] } } } </script> <style lang="stylus"> /*...*/ </style> //commonLabel.vue ǩ <template> <div class="label-item-wrapper" title="ģ" draggable="true" @dragstart="dragStart"> <img class="label-icon" alt="{{title}}" :src="iconUrl"> <span class="label-text">{{title}}</span> </div> </template> <script> //mixin import labelMixin from './mixin/labelMixin' export default { name : "label", props : { title : String, type : String }, mixins : [labelMixin], computed : { iconUrl (){ return this.type + '.png' } } } </script> <style lang="stylus"> /*...*/ </style> //labelMixin.js import typeDataMap from './typeDataMap' export default { methods : { dragStart (e){ var id = parseInt(Date.now() + "" + parseInt(Math.random() * 90)) var widgetData = typeDataMap[this.type] var dt = e.dataTransfer widgetData['id'] = id dt.setData("id", id) dt.setData("type", this.type) dt.setData("widgetData", JSON.stringify(widgetData)) } } } Ԥ ԤԽϼ򵥣ݵİ󶨣϶϶ʵͨhtml5ԭdrag¼vueԭ϶ʱ򲢲ҪȥֶıԤڸDOM˳ֻҪıݶindexɣݵı仯ᷴӦDOMϡ򵥵ĽڱԤ <template> <div class="preview-item-wrapper" draggable="true" :class="{'active': isActive}" @click="showEdit" @dragover="allowDrop" @dragstart="dragStart" @drop="dropIn" > <span class="preview-item-del" :class="{'active': isActive}" title="ɾ"> <div v-on:click="delMe">x</div> </span> <label class="preview-item-label">- ڱ -</label> <div class="preview-item-input-wrapper"> <div class="title-text">{{text}}</div> </div> </div> </template> <script> //action import {addPreviewAndData, deleteWidgetPreview, changeWidgetEdit, changPreviewAndDataIndex} from '../../../store/actions' //mixin import previewMixin from './mixin/previewMixin' export default { name : "sectionTitle_preview", mixins : [previewMixin], props : { id : Number, alphabetize : Number }, computed : { //mixin˽ text (){ for (let value of this.widgetDataArr) if (value.id == this.id) return value.text } }, vuex : { //mixinҪԺͷ getters : { widgetDataArr : (state) => state.widgetDataArr, currentEditWidgetId : (state) => state.currentEditWidgetId }, deportment : { addPreviewAndData, deleteWidgetPreview, changeWidgetEdit, changPreviewAndDataIndex } } } </script> <style lang="stylus"> /*...*/ </style> /** * previewMixin.js * Ԥmixin * @ȡ֮ͬɸõļ뷽 */ export default { computed : { //ԤǷΪǰ isActive (){ return this.id == this.currentEditWidgetId } }, methods : { //ɾԤ delMe (){ this.deleteWidgetPreview(this.id) }, //ʾԤӦı༭ showEdit (){this.changeWidgetEdit(this.id) }, //ԤϷ allowDrop (e){ e.preventDefault(); }, //ʼϷŸԤ dragStart (e){ var dt = e.dataTransfer dt.setData("index", this.index) }, //ԤϷ(Ԥ߱ǩ) dropIn (e){ e.preventDefault() e.stopPropagation() var dt = e.dataTransfer var id = parseInt(dt.getData("id")) if (id){ //idDZǩ var type = dt.getData("type") var widgetData = JSON.parse(dt.getData("widgetData"))this. changeWidgetEdit(id) this.addValidation(id) //֤ } else { var alphabetize = parseInt(dt.getData("index")) this.changPreviewAndDataIndex(index, this.index) } //dataTransfer dt.clearData() } } } ༭ ԽڱΪ <template> <div class="edit-item-wrapper"> <label class="edit-item-label">ڱı</label> <validator name="titleValidator"> <div class="edit-item-input-wrapper"> <textarea class="title-edit-input" placeholder="16" v-model="text" v-validate:text="{ required: {rule: true,message: 'дڱı'}, maxlength: {rule: 16,message: 'ڱı16'} }" @input="inputValue" @valid="onValid" @invalid="onInvalid" ></textarea> <div class="edit-input-err" v-if="$titleValidator.text.required"> {{$title Validator.text.required}}</div> <div class="edit-input-err" v-if="$titleValidator.text.maxlength"> {{$title Validator.text.maxlength}}</div> </div> </validator> </div> </template> <script> //action import {changeWidgetData, changeValidation} from '../../../store/actions' //mixin import editMixin from './mixin/editMixin' export default { name : "title_edit", mixins : [editMixin], props : { id : Number }, computed : { //mixin˽ text (){ for (let value of this.widgetDataArr) if (value.id == this.id) return value.text } }, methods : { //mixin˽з inputValue (e){ this.changeWidgetData(this.id, 'text', e.target.value) } }, vuex : { getters : { widgetDataArr : (state) => state.widgetDataArr }, deportment : { changeWidgetData, changeValidation } } } </script> <style lang="stylus"> /*...*/ </style> /** * editMixin.js * ༭mixin */ export default { data (){ return { //isValid : false } }, methods : { onValid (){ //֤ͨ this.isValid = true this.changeValidation(this.id, true) }, onInvalid (){ //֤ʧ this.isValid = false this.changeValidation(this.id, false) } } } һЩԼstoreȾͲٽˣǰĽѻ͵ˡɺģ չʾ ڱ༭󣬱ûIDһݶ鵽serverݿС˾ĻH5ģH5ҳ水IDserverȡûݣе˳ȾɶӦH5ҳ档ȻH5ҲҪһʵַͳһӦԵ淶ȡ ģijǶԻݽṹĸ߶ȳټÿΪ൱reactеDOMһjavascriptάһ׳ݽṹκζõṹ԰ȾҪչʾĶreactӦģjsxĽṹڱ󱻳DOMwebDOMȾhtmlṹ(react js)ֻnativeˣDOMȾnativeṹ(react native)Ҳ˵luaˣwpf(ܵĻ)ҲӳǵṹʵҲеڷ˵DAO㣬ͳһݷʽӿڣײʲôݿлȿܻ˵Ŀش       69  :     Androidֻһ Javascript ǵajaxʵ ׵Ajax javascript ʹCookies ʹ jQuery Ajax ...    ѵγ Struts+Spring+Hibernate J2EEWeb 2.0Ӧÿ J2EEģʽܵ Java EE 5ҵܹ JavaԪԷ뼼 Java̷뼼 γ...    ɹ GE ʵѵ ƹijӹ˾ Nodejs߼Ӧÿ ʢ滪 ׿Խ߱߱ ijϢ˾ Pythonѵ ijITϵͳ Բ йʴ Գģͼ(TMMI) Ժ ƷƷ ...          ÿ2ĵ/Ƶ ɨ΢Ŷά붩 ļ¿ ÿ300Դ     | ϵ | ICP10020922 110108001071