Search Preview
VUE.JS组件化开发实践
uml.org.cnbody { 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 |
|
||||||
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--火龙果软件工程技术中心
一文深入了解:分布式系统中的缓存架构-数据库
基于 Bitbucket Pipeline + Amazon S3 的自动化运维体系-IT运维管理
DAGOR:微信微服务过载控制系统-移动端开发
数据库-火龙果软件工程
IT运维管理-火龙果软件工程
微服务-火龙果软件工程
理解vuex的状态管理模式架构
运用TensorFlow处理简单的NLP问题-人工智能-火龙果软件
JavaScript-火龙果软件工程
人工智能-火龙果软件工程
从系统和代码实现角度解析TensorFlow的内部实现原理-人工智能-火龙果软件
使用IPython增强交互式体验-Python
在 IBM Cloud 上创建和部署区块链聊天应用
python-火龙果软件工程
云计算-火龙果软件工程
VUE.JS组件化开发实践
瑞萨C++多线程开发培训-火龙果软件
产品经理产品管理培训| 产品经理培训
使用Selenium进行有效的自动化测试-火龙果软件-UML软件工程组织
高可用架构培训|软件架构培训-火龙果软件
基于UML+EA进行嵌入式系统分析设计培训-火龙果软件-UML软件工程组织
工作量估算管理培训-火龙果软件
培训案例-火龙果软件
软件架构师认证|软件架构师培训-火龙果软件
软件架构师认证|软件架构师培训-火龙果软件
软件架构师认证|软件架构培训-火龙果软件
软件架构师认证|软件架构师培训-火龙果软件
Github使用快速上手-配置管理
用 Vuex 构建一个笔记应用 -web开发
配置管理-火龙果软件工程
基于matplotlib的数据可视化 -Python
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 pollyfillshimûġҲΪʲôVue֧IE8°汾ԭΪIE8definePropertyֻ֧DOMObjectᱨ)ڲʵռʹ֧ǶĶṹ飬ͨĿɱ䷽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ɷӦmutaionstateַʽȷж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