requirejs vue vue.router簡單框架
index.html 入口頁面
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>vue</title> <link href="../css/index.css" rel="stylesheet"> <script class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="../dist/js/requirejs-2.1.22.js"></script> <script class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="../js/common/base.js"></script></head><body> <div class="panel" id="app"> <div class="panel-left"> <ul class="menus"> <li v-for="menu in menus"><a v-on:click="switchPage(menu)">`menu`.`name`</a></li> </ul> </div><!-- panel-left --> <div class="panel-right"> <router-view></router-view> </div> </div><!-- panel --></body></html>
base.js requirejs 配置檔案
(function(){ requirejs.config({ baseUrl: "../js", paths:{ "promise":"../dist/js/q", "vue":"../dist/js/vue", "vue.router":"../dist/js/vue-router.min", "text":"../dist/js/text", "css":"../dist/js/css.min" }, waitSeconds: 15, map:{ }, urlArgs: "version=" + Date.now(), shim: { promise:{ exports:"Q" }, "vue": { exports: "Vue" }, "vue.router": { exports: "VueRouter" } }, callback:function(){ }, deps:["vue","vue.router","promise","index"] // 預設要載入的js });})();
index.js vue 入口
define(["vue","vue.router","common/routes"], function(Vue,VueRouter,routes) { Vue.use(VueRouter); var data = { menus: [ {path: "/account", name: "賬戶管理"}, {path: "/authorization", name: "許可權管理"}, {path: "/member", name: "會員管理"} ] }; var router = new VueRouter({ routes:routes }); var methods = { switchPage:function(menu){ console.log(menu); this.$router.push(menu.path); } }; var app = new Vue({ router:router, el:"#app", data:data, methods:methods });});
routes.js 路由配置
define(["common/ResolveComponent"], function(ResolveComponent) { var routes = []; routes.push({ path: '/account', component: ResolveComponent("account/account_index") }); routes.push({ path: '/authorization', component: ResolveComponent("authorization/authorization_index") }); routes.push({ path: '/member', component: ResolveComponent("member/member_index") }); return routes;});
ResolveComponent.js component懶載入工具
define(["require","promise"], function(require,Q) { var resolve = function(dependency){ return function(){ if(!(dependency instanceof Array)){ dependency = [dependency]; } var deferred = Q.defer(); require(dependency,function(res){ deferred.resolve(res); }); return deferred.promise; } }; return resolve;});
account_index.js
define(["text!../../pages/account/account_index.html","css!../../css/account/account_index.css"], function(template) { var data = { list:[ {id:"001",name:"小王"}, {id:"002",name:"大王"}, {id:"003",name:"老王"} ] }; var methods = { say:function(item){ alert("我居然是"+item.name); } }; return { methods:methods, template:template, data:function(){ return data } }});
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1727/viewspace-2816984/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- vue框架的簡單使用Vue框架
- 基於requirejs的vue2專案 (三)UIJSVue
- vue+vux-ui+axios+mock搭建一個簡單vue框架VueUXUIiOSMock框架
- 理解vue ssr原理,自己搭建簡單的ssr框架Vue框架
- spingMVC框架簡單配置MVC框架
- Vue簡單的使用Vue
- Vue簡單入門Vue
- 基於vue實現一個簡單的MVVM框架(原始碼分析)VueMVVM框架原始碼
- 從零到一實現類vue2.*的簡單MVVM框架VueMVVM框架
- pythontonado框架簡單應用Python框架
- avalon框架,簡單的MVVM框架MVVM
- 簡單易懂的JSON框架JSON框架
- Gin 框架的簡單搭建框架
- 一個簡簡單單的紅點系統框架框架
- 簡簡單單的Vue2(簡單語法,生命週期,元件)Vue元件
- 自制簡單的Tabs(Vue)Vue
- vue簡單模板語法Vue
- 簡單的實現vue原理Vue
- vue cli 3的簡單理解Vue
- CI 框架簡單入門筆記框架筆記
- 關於 PHP 框架的簡單思考PHP框架
- 簡單vue專案腳手架Vue
- vue+sortablejs的簡單使用模板VueJS
- 一個簡單vue.config.js配置和axios簡單封裝VueJSiOS封裝
- 簡易版的Spring框架之IOC簡單實現Spring框架
- Feacar分散式事務框架簡單使用分散式框架
- PHP單一檔案入口框架簡析PHP框架
- 徒手擼一個簡單的RPC框架RPC框架
- SpringBoot 框架MongoDB 簡單的查詢方式Spring Boot框架MongoDB
- 一個很簡單的PHP框架lyuePHP框架
- 簡單談談Hilt——依賴注入框架依賴注入框架
- Swift 超簡單的驗證框架ValidateSwiftSwift框架
- Spring Boot:簡單使用EhCache快取框架Spring Boot快取框架
- 快速上手python的簡單web框架flaskPythonWeb框架Flask
- 簡易版的Spring框架之AOP簡單實現(對我來說不簡單啊)Spring框架
- 簡單介紹 Vue 3.0 專案建立Vue
- 簡單的 Vue.js 入門方法Vue.js
- 手寫一個超簡單的VueVue