From 452e55b192fee71e90d8789c087670ace736d3c9 Mon Sep 17 00:00:00 2001 From: xsf <416175716@qq.com> Date: Thu, 18 Aug 2016 17:47:12 +0800 Subject: [PATCH] 20160818/17:47 --- .gitignore | 4 + .idea/encodings.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/vue-vueRouter-webpack.iml | 11 + .idea/workspace.xml | 669 ++++++++++++++++++++++++++++++++ Vue教程.md | 65 ++++ index.html | 15 + index.tpl | 11 + package.json | 46 +++ readme.md | 58 +++ src/app.js | 33 ++ src/app.vue | 73 ++++ src/components/select.vue | 109 ++++++ src/css/animate.css | 165 ++++++++ src/css/b.css | 3 + src/css/common.css | 81 ++++ src/css/testInAbout.css | 19 + src/filters.js | 78 ++++ src/images/logo.png | Bin 0 -> 11460 bytes src/routers.js | 76 ++++ src/views/about.vue | 27 ++ src/views/home.vue | 21 + src/views/index.vue | 106 +++++ src/views/my_views.vue | 98 +++++ src/views/news.vue | 38 ++ src/views/search.vue | 17 + vueComponent.sublime-snippet | 59 +++ webpack.config.js | 135 +++++++ 约定.md | 144 +++++++ 30 files changed, 2181 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/vue-vueRouter-webpack.iml create mode 100644 .idea/workspace.xml create mode 100644 Vue教程.md create mode 100644 index.html create mode 100644 index.tpl create mode 100644 package.json create mode 100644 readme.md create mode 100644 src/app.js create mode 100644 src/app.vue create mode 100644 src/components/select.vue create mode 100644 src/css/animate.css create mode 100644 src/css/b.css create mode 100644 src/css/common.css create mode 100644 src/css/testInAbout.css create mode 100644 src/filters.js create mode 100644 src/images/logo.png create mode 100644 src/routers.js create mode 100644 src/views/about.vue create mode 100644 src/views/home.vue create mode 100644 src/views/index.vue create mode 100644 src/views/my_views.vue create mode 100644 src/views/news.vue create mode 100644 src/views/search.vue create mode 100644 vueComponent.sublime-snippet create mode 100644 webpack.config.js create mode 100644 约定.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8883194 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +build/ +d.html +npm-debug.log diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..66f26e7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vue-vueRouter-webpack.iml b/.idea/vue-vueRouter-webpack.iml new file mode 100644 index 0000000..d7a18b1 --- /dev/null +++ b/.idea/vue-vueRouter-webpack.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..7d5738c --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,669 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $PROJECT_DIR$ + true + + bdd + + DIRECTORY + + false + + + + + + + + + + + + + + + + + + + 1471498492040 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Vue教程.md b/Vue教程.md new file mode 100644 index 0000000..ba72f4b --- /dev/null +++ b/Vue教程.md @@ -0,0 +1,65 @@ +#Vue教程 + +[细节与最佳实践](http://vuejs.org/guide/best-practices.html) + +[Vue1.0.x文档](http://vuejs.org/) + +[Vue1.0.x绑定语法参考](https://github.com/vuejs/vue/issues/1325) + +[每次更新的变化](https://github.com/vuejs/vue/releases) + +与webpack 一起使用所需插件 + +[vue-loader-example](https://github.com/vuejs/vue-loader-example) + +[vue-html-loader](https://github.com/vuejs/vue-html-loader) + +####文章 +`尤小右` + +[Vue.js:轻量高效的前端组件化方案](http://www.csdn.net/article/1970-01-01/2825439) + +`勾三股四` + +[Vue + webpack 项目实践](http://jiongks.name/blog/just-vue/) + +[Vue.js 源码学习笔记](http://jiongks.name/blog/vue-code-review/) + +`稀土掘金` + +[Vue 组件化开发实践](http://ftandy.github.io/2015/09/05/vue/) + +`Randy` + +[Vue.js 和 Webpack(一)为什么使用Vue](http://djyde.github.io/2015/08/29/vuejs-and-webpack-1.html) + +[Vue.js 和 Webpack(二)使用webpack](http://djyde.github.io/2015/08/30/vuejs-and-webpack-2.html) + +[Vue.js 和 Webpack(三)Vue.js + Webpack](http://djyde.github.io/2015/08/31/vuejs-and-webpack-3.html) + +#webpack教程 +[learn-webpack](http://vingojw.github.io/2015/08/19/learn-webpack/) + +#Vue-router教程 +[中文文档](http://vuejs.github.io/vue-router/zh-cn/index.html) - [英文文档](http://vuejs.github.io/vue-router/en/index.html) +[学习笔记](https://github.com/vingojw/learn-vue-router) + +#技术交流 + +[Vue技术论坛](http://forum.vuejs.org/) + +[Vue的聊天室,很多人在里面讨论并解决问题](https://gitter.im/vuejs/vue) + +#demo + +[qingcheng](https://github.com/zerqu/qingcheng) + +[vue-strap 用vue实现bootstrap](https://github.com/yuche/vue-strap) + +[vue-mui](https://github.com/mennghao/vue-mui) + +[通过学习(copy)以上两个demo,使用 Vue1.0 + VueRouter + webpack](https://github.com/vingojw/vue-vueRoute-webpack) + +[Chat by Vue + Webpack](https://github.com/Coffcer/vue-chat) + +[用Vue实现的拖拽效果](http://jsfiddle.net/lain8dono/mrnyf79e/) \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..f0ded4c --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + + + + + + 首页 + + + + +
+ + diff --git a/index.tpl b/index.tpl new file mode 100644 index 0000000..bb7ce37 --- /dev/null +++ b/index.tpl @@ -0,0 +1,11 @@ + + + + + + + + +
+ + diff --git a/package.json b/package.json new file mode 100644 index 0000000..b5445bd --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "learn-webpack", + "version": "1.0.0", + "main": "index.js", + "dependencies": { + "extract-text-webpack-plugin": "^0.8.2" + }, + "devDependencies": { + "babel-core": "^6.3.17", + "babel-loader": "^6.2.0", + "babel-plugin-transform-runtime": "^6.3.13", + "babel-preset-es2015": "^6.3.13", + "babel-runtime": "^5.8.34", + "css-loader": "^0.23.0", + "cssnext-loader": "^1.0.1", + "fastclick": "^1.0.6", + "file-loader": "^0.8.4", + "hammerjs": "^2.0.6", + "html-loader": "^0.3.0", + "html-webpack-plugin": "^1.6.2", + "jshint-loader": "^0.8.3", + "style-loader": "^0.13.0", + "swiper": "^3.2.0", + "url-loader": "^0.5.6", + "vue": "^1.0.20", + "vue-hot-reload-api": "^1.2.2", + "vue-html-loader": "^1.1.0", + "vue-loader": "^8.2.0", + "vue-router": "^0.7.11", + "vue-style-loader": "^1.0.0", + "webpack": "^1.12.9", + "webpack-dev-server": "^1.14.0", + "webpack-zepto": "0.0.1" + }, + "scripts": { + "mb": "export PRODUCTION=1 && webpack --progress --hide-modules", + "wb": "set PRODUCTION=1 && webpack --progress --hide-modules", + "start": "webpack-dev-server --progress --profile --colors --inline ", + "port": "webpack-dev-server --progress --colors --inline --port 9090 ", + "hot": "webpack-dev-server --progress --colors --inline --hot", + "cp": "cp -r index.html ./build/ d:/wamp/www/vue", + "ip": "webpack-dev-server --progress --colors --hot --host=0.0.0.0 --port 9000" + }, + "author": "", + "license": "ISC" +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4160072 --- /dev/null +++ b/readme.md @@ -0,0 +1,58 @@ +## Setup +``` bash +npm install +npm start +``` +访问 localhost:8080 + +如果想在手机上查看 + +``` +npm run ip +``` +访问 你本地的ip:9000 + +## 版本控制,打包压缩 +MAC + +``` +npm run mb +``` + +windows + +``` +npm run wb +``` + +## 目录结构 +
+│  .gitignore          # 忽略无需git控制的文件  比如 node_modules
+│  package.json        # 项目配置
+│  readme.md           # 项目说明
+│  index.html          # 首页
+│  index.tpl           # 首页模板  在发布的时候 执行 PRODUCTION=1 webpack 会生成一个d.html并注入脚本,样式,达到版本控制的目的
+│  webpack.config.js   # webpack 配置文件
+│
+├─node_modules
+└─src
+    │  app.js          # 启动配置,配置路由,过滤器
+    │  app.vue         # 主vue
+    │  filters.js      # 过滤器
+    │  routers.js      # 路由
+    │
+    ├─components       # 组件
+    │      my-component.vue
+    │
+    ├─css              # 公用样式
+    │      common.css
+    │
+    └─views            # 页面
+            about.vue
+            home.vue
+            not-found.vue
+
+ +##学习参考: +待续 + diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..c8632c0 --- /dev/null +++ b/src/app.js @@ -0,0 +1,33 @@ + +require('./css/common.css');//加载公共样式 +require('./css/animate.css');//加载公共样式 + +var Vue = require('vue'); +var VueRouter = require('vue-router'); +var fastclick = require('fastclick'); +fastclick.attach(document.body); + +// register filters 自定义过滤器 金额格式化, +var filters = require('./filters'); + +Object.keys(filters).forEach(function(k) { + Vue.filter(k, filters[k]); +}); + +var App = Vue.extend(require('./app.vue')); + Vue.use(VueRouter); + +var router = new VueRouter( + { + hashbang: true, //为true的时候 example.com/#!/foo/bar , false的时候 example.com/#/foo/bar + //abstract:true, //地址栏不会有变化 + //以下设置需要服务端设置 + //history: false, //当使用 HTML5 history 模式时,服务器需要被正确配置 以防用户在直接访问链接时会遇到404页面。 + //saveScrollPosition: false + linkActiveClass:'custom-active-class' //全局设置连接匹配时的类名 参考http://vuejs.github.io/vue-router/en/link.html + } +); + +require('./routers')(router); + +router.start(App,'#app'); \ No newline at end of file diff --git a/src/app.vue b/src/app.vue new file mode 100644 index 0000000..159d606 --- /dev/null +++ b/src/app.vue @@ -0,0 +1,73 @@ + + + + diff --git a/src/components/select.vue b/src/components/select.vue new file mode 100644 index 0000000..0a92f07 --- /dev/null +++ b/src/components/select.vue @@ -0,0 +1,109 @@ + + + + + \ No newline at end of file diff --git a/src/css/animate.css b/src/css/animate.css new file mode 100644 index 0000000..cbe0be1 --- /dev/null +++ b/src/css/animate.css @@ -0,0 +1,165 @@ +/*所有的动画*/ + .slideleft-enter { + animation:slideleft-in .3s; + } + .slideleft-leave { + animation:slideleft-out .3s; + } + .slideright-enter { + animation:slideright-in .3s; + } + .slideright-leave { + animation:slideright-out .3s; + } + .slidetop-enter { + animation:slidetop-in .3s; + } + .slidetop-leave { + animation:slidetop-out .3s; + } + .slidebottom-enter { + animation:slidebottom-in .3s; + } + .slidebottom-leave { + animation:slidebottom-out .3s; + } + @keyframes slideleft-in { + 0% { + transform: translateX(-100%); + opacity: 0; + } + 100% { + transform: translateX(0); + opacity: 1; + } + } + + @keyframes slideleft-out { + 0% { + transform: translateX(0); + opacity: 1; + } + 100% { + transform: translateX(-100%); + opacity: 0; + } + } + + @keyframes slideright-in { + 0% { + transform: translateX(100%); + opacity: 0; + } + 100% { + transform: translateX(0); + opacity: 1; + } + } + + @keyframes slideright-out { + 0% { + transform: translateX(0); + opacity: 1; + } + 100% { + transform: translateX(100%); + opacity: 0; + } + } + @keyframes slidetop-in { + 0% { + transform: translateY(-100%); + opacity: 0; + } + 100% { + transform: translateX(0); + opacity: 1; + } + } + + @keyframes slidetop-out { + 0% { + transform: translateX(0); + opacity: 1; + } + 100% { + transform: translateY(-100%); + opacity: 0; + } + } + @keyframes slidebottom-in { + 0% { + transform: translateY(100%); + opacity: 0; + } + 100% { + transform: translateX(0); + opacity: 1; + } + } + @keyframes slidebottom-out { + 0% { + transform: translateX(0); + opacity: 1; + } + 100% { + transform: translateY(100%); + opacity: 0; + } + } + + +/*切换效果 -- 渐隐*/ +.fadein-enter{ + animation:fadein-in 0.3s ease; +} +.fadein-leave{ + animation:fadein-out 0.3s ease; +} + +/*切换效果 -- 从右渐入*/ +.fadeInRight-enter { + animation:fadeInRight-in 0.3s ease; +} +.fadeInRight-leave{ + animation:fadeInRight-out 0.3s ease; +} + +@keyframes fadein-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +@keyframes fadein-out { + 0% { + opacity: 1; + } + 100% { + opacity: 0; + } +} +@keyframes fadeInRight-in { + 0% { + opacity: 0; + transform: translate3d(2000px,0,0) + } + + 100% { + opacity: 1; + transform: none + } +} +@keyframes fadeInRight-out { + 0% { + opacity: 1; + transform: none + } + + 100% { + opacity: 0; + transform: translate3d(-2000px,0,0) + } +} diff --git a/src/css/b.css b/src/css/b.css new file mode 100644 index 0000000..a4e9078 --- /dev/null +++ b/src/css/b.css @@ -0,0 +1,3 @@ +.bbb{ + background:black; +} \ No newline at end of file diff --git a/src/css/common.css b/src/css/common.css new file mode 100644 index 0000000..c1869ca --- /dev/null +++ b/src/css/common.css @@ -0,0 +1,81 @@ +@charset "utf-8"; +@charset "utf-8"; + +/*清零*/ +body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { margin:0; padding:0;} +fieldset,img { border:0;} +ol,ul { list-style:none; } +h1,h2,h3,h4,h5,h6,button,input,select,textarea { font-size:100%; + font-weight: normal; } +button::-moz-focus-inner,input::-moz-focus-inner{ padding:0; border:0; } +table{ border-collapse: collapse; border-spacing: 0; } +i, cite, em, var, dfn, address { font-style: normal; } +body{ font:14px "方正兰亭细黑简体","微软雅黑","宋体",Arial;} +a{ text-decoration:none; outline: none;} +a:hover{ text-decoration: none; } +a:active, a:focus{ outline:none; } +b{ font-weight: normal; } +input ,button{ border: none; outline: none;} +input:not([type="radio"]){appearance:none;-webkit-appearance:none;-o-appearance:none;-moz-appearance:none;} +button:active{ + transform:scale(0.9); + -webkit-transform: scale(0.9); + -moz-transform: scale(0.9); + -ms-transform: scale(0.9); + -o-transform: scale(0.9); +} +textarea{ + appearance: none; + -webkit-appearance: none; + -moz-appearance: none; + -o-appearance: none; + resize: none; +} +input{ + border-radius: 0; +} + +*{ + box-sizing: border-box; +} + +a{ + color: #232323; +} +button{ + background: none; +} + + +@font-face { + font-family: "iconfont"; + src: require('iconfont.woff') format('woff'), + require('iconfont.ttf') format('truetype'), + require('iconfont.svg#iconfont') format('svg'); +} + +.iconfont { + font-family:"iconfont" !important; + font-style:normal; + -webkit-font-smoothing: antialiased; + -webkit-text-stroke-width: 0.2px; + -moz-osx-font-smoothing: grayscale; +} + +[v-cloak] { + display: none; +} + +.col2{ + width: 50%; +} +.col3{ + width: 33.33%; +} +.col4{ + width: 25%; +} +.col6{ + width: 16.66%; +} + diff --git a/src/css/testInAbout.css b/src/css/testInAbout.css new file mode 100644 index 0000000..71dc434 --- /dev/null +++ b/src/css/testInAbout.css @@ -0,0 +1,19 @@ +h2{ + font-size: 28px; + text-align: center; +} +span{ + font-size: 15px; + color: red; +} +p{ + font-size: 14px; + text-align: center; +} +.about img{ + width: 180px; + margin-top: 70px; +} +.about{ + padding-top: 15px; +} \ No newline at end of file diff --git a/src/filters.js b/src/filters.js new file mode 100644 index 0000000..e4182bc --- /dev/null +++ b/src/filters.js @@ -0,0 +1,78 @@ + + +function timeago(time) { + time = new Date(time); + var delta = parseInt((new Date() - time) / 1000, 10); + if (delta <= 0) return 'just now'; + + var minutes = delta / 60; + if (minutes < 1) return 'less than a minute ago'; + if (minutes < 2) return 'about a minute ago'; + + var hours = minutes / 60; + if (hours < 1) return parseInt(minutes, 10) + ' minutes ago'; + if (hours < 1.5) return 'about an hour ago'; + + var days = hours / 24; + if (days < 1) return Math.round(hours) + ' hours ago'; + if (days < 7) return parseInt(days, 10) + ' days ago'; + + var month = time.getMonth(); + if (month < 10) month = '0' + month; + var date = time.getDate(); + if (date < 10) date = '0' + date; + return [time.getFullYear(), month, date].join('-'); +} + + +function urlize(text) { + if (!text) return ''; + var pattern = /https?:\/\/[^\s<]+[^<.,:;"')\]\s]/g; + return text.replace(pattern, function(u) { + var t = u.replace('http://', ''); + return '' + t + ''; + }); +} + +//获取图片地址,如果地址带有 http://那么就认为是绝对地址,然后直接返回 +function imgUrl(url){ + if(url.match(/http:\/\//)){ + return url; + } + + //全站统一配置,页面首先会引用 + if(window.abp){ + return window.abp.imageDomain + url; + } + var testUrl = 'http://img.yaomaiche.com'; //此url到时候走配置 + + if(this.isTest){ + testUrl = 'http://img.test.yaomaiche.com'; + } + return testUrl + url; +} + + +//显示价格 +function price(value,currency){ +var digitsRE = /(\d{3})(?=\d)/g + value = parseFloat(value) + if (!isFinite(value) || (!value && value !== 0)) return '' + currency = currency != null ? currency : '¥' + var stringified = Math.abs(value).toFixed(2) + var _int = stringified.slice(0, -3) + var i = _int.length % 3 + var head = i > 0 + ? (_int.slice(0, i) + (_int.length > 3 ? ',' : '')) + : '' + var _float = stringified.slice(-3) + var sign = value < 0 ? '-' : '' + return currency + sign + head + + _int.slice(i).replace(digitsRE, '$1,') + + _float +} + +exports.imgUrl = imgUrl; +exports.price = price; +exports.timeago = timeago; +exports.urlize = urlize; diff --git a/src/images/logo.png b/src/images/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..8bbf984157a465f7280d556a754ebce1b5274c0c GIT binary patch literal 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c=u Q0;qtfDQPQK$Xh-7e+`t7*Z=?k literal 0 HcmV?d00001 diff --git a/src/routers.js b/src/routers.js new file mode 100644 index 0000000..242245b --- /dev/null +++ b/src/routers.js @@ -0,0 +1,76 @@ +module.exports = function(router){ + router.map({ + '/':{ + name:'index', + component: require('./views/index.vue') + }, + '/news':{ + name:'news', + component: function(reslove){ + return require(['./views/news.vue'],reslove) + } + }, + '/search': { + name:'search', + component: require('./views/search.vue') + }, + '/about/:viewId': { + name:'about', + component: require('./views/about.vue'), + auth: true // 此页面需要用户登录 + }, + '/my_views': { + name:'my_views', + component: require('./views/my_views.vue') + }, + }); + + window.routeList=[]; + + router.beforeEach(function(transition){ + console.log(11111); + console.log('before---------------'); + //可以通过在路由中的自定义字段来验证用户是否需要登陆 + // if(transition.to.auth){ + // console.log('通过配置路由中自定义的字段验证是否需要登陆'); + // } + + // //如果是中止,这里可以判断用户登录 + // //if(transition.to.path === '/forbidden'){ + if(transition.to.name == 'forbidden'){ + router.app.authenticating = true + setTimeout(function(){ + router.app.authenticating = false + alert('此路由在全局中设置为中止'); + transition.abort(); + },1500); + } + + if(routeList.length > 1 && transition.to.name==routeList[routeList.length-2]['name']){ + router.app.effect='back'; + routeList.splice(routeList.length-1,1); + console.log(routeList); + } else { + router.app.effect='fade'; + routeList.push({ + name : transition.to.name, + path : transition.to.path, + query : transition.to.query, + params : transition.to.params, + timer: +new Date + }); + } + + setTimeout(function(){ + transition.next(); + },00); + }); + + //可以记录访问路径 + router.afterEach(function(transition){ + console.log('-----------------after'); + for (var i = 0; i < routeList.length; i++) { + console.log(routeList[i].name); + }; + }); +} \ No newline at end of file diff --git a/src/views/about.vue b/src/views/about.vue new file mode 100644 index 0000000..cc6a800 --- /dev/null +++ b/src/views/about.vue @@ -0,0 +1,27 @@ + + + \ No newline at end of file diff --git a/src/views/home.vue b/src/views/home.vue new file mode 100644 index 0000000..52d1ce4 --- /dev/null +++ b/src/views/home.vue @@ -0,0 +1,21 @@ + + + \ No newline at end of file diff --git a/src/views/index.vue b/src/views/index.vue new file mode 100644 index 0000000..8a334e2 --- /dev/null +++ b/src/views/index.vue @@ -0,0 +1,106 @@ + + + + \ No newline at end of file diff --git a/src/views/my_views.vue b/src/views/my_views.vue new file mode 100644 index 0000000..180431d --- /dev/null +++ b/src/views/my_views.vue @@ -0,0 +1,98 @@ + + + + \ No newline at end of file diff --git a/src/views/news.vue b/src/views/news.vue new file mode 100644 index 0000000..e888e69 --- /dev/null +++ b/src/views/news.vue @@ -0,0 +1,38 @@ + + + + + \ No newline at end of file diff --git a/src/views/search.vue b/src/views/search.vue new file mode 100644 index 0000000..b6ebd59 --- /dev/null +++ b/src/views/search.vue @@ -0,0 +1,17 @@ + + + \ No newline at end of file diff --git a/vueComponent.sublime-snippet b/vueComponent.sublime-snippet new file mode 100644 index 0000000..b72ee12 --- /dev/null +++ b/vueComponent.sublime-snippet @@ -0,0 +1,59 @@ + + + + + + + + +]]> + + vueComponent + diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..37f2601 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,135 @@ +//先清空 n-build 文件夹下的文件 +var fs = require('fs'),buildPath='./build/'; +var folder_exists = fs.existsSync(buildPath); +if(folder_exists == true) +{ + var dirList = fs.readdirSync(buildPath); + dirList.forEach(function(fileName) + { + fs.unlinkSync(buildPath + fileName); + }); + console.log("clearing " + buildPath); +}; + +//readfile +//先把index.html里面关于style和js的hash值都删除掉,避免在使用 npm run dev 的时候,路径还是压缩后的路劲 +fs.readFile("index.html",'utf-8',function(err,data){ + if(err){ + console.log("error"); + }else{ + //将index.html里面的hash值清除掉 + var devhtml = data.replace(/((?:href|src)="[^"]+\.)(\w{20}\.)(js|css)/g, '$1$3'); + fs.writeFileSync('index.html', devhtml); + } +}); + +var webpack = require('webpack'); + +//var vue = require("vue-loader"); + + +//混淆压缩 +var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin; + +//检测重用模块 +var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin; + +//独立样式文件 +var ExtractTextPlugin = require("extract-text-webpack-plugin"); + + + +// 在命令行 输入 “PRODUCTION=1 webpack --progress” 就会打包压缩,并且注入md5戳 到 index.html里面 +var production = process.env.PRODUCTION; + +var plugins = [ + //会将所有的样式文件打包成一个单独的style.css + new ExtractTextPlugin( production ? "style.[hash].css" : "style.css" , { + disable: false//, + //allChunks: true //所有独立样式打包成一个css文件 + }), + //new ExtractTextPlugin("[name].css" ) + //自动分析重用的模块并且打包成单独的文件 + new CommonsChunkPlugin(production ? "vendor.[hash].js" : "vendor.js" ), + function(){ + return this.plugin('done', function(stats) { + var content; + //这里可以拿到hash值 参考:http://webpack.github.io/docs/long-term-caching.html + content = JSON.stringify(stats.toJson().assetsByChunkName, null, 2); + console.log('版本是:'+JSON.stringify(stats.toJson().hash)); + //return fs.writeFileSync('build/assets.json', content); + }); + } +]; + +//发布编译时,压缩,版本控制 +if (process.env.PRODUCTION) { + //压缩 + plugins.push(new webpack.optimize.UglifyJsPlugin({compress: {warnings: false } })); +} + +/* + 版本控制 + package.json中的 + "html-webpack-plugin": "^1.6.2", + 模块是把生成的带有md5戳的文件,插入到index.html中。 + 通过index.tpl模板,生成 index.html + */ +var HtmlWebpackPlugin = require("html-webpack-plugin"); +//HtmlWebpackPlugin文档 https://www.npmjs.com/package/html-webpack-plugin +//https://github.com/ampedandwired/html-webpack-plugin/issues/52 +plugins.push( new HtmlWebpackPlugin({ + filename:'../index.html',//会生成index.html在根目录下,并注入脚本 + template:'index.tpl', + inject:true //此参数必须加上,不加不注入 +})); + + +module.exports = { + entry: ["./src/app.js"], + output: { + path: "./build", + /* + publicPath路径就是你发布之后的路径, + 比如你想发布到你站点的/util/vue/build 目录下, 那么设置 + publicPath: "/util/vue/build/", + 此字段配置如果不正确,发布后资源定位不对,比如:css里面的精灵图路径错误 + */ + publicPath: "/build/", + filename: production ? "build.[hash].js" : "build.js"//"build.[hash].js"//[hash]MD5戳 解决html的资源的定位可以使用 webpack提供的HtmlWebpackPlugin插件来解决这个问题 见:http://segmentfault.com/a/1190000003499526 资源路径切换 + }, + module: { + preLoaders:[ + // { + // //代码检查 + // test:/\.js$/,exclude:/node_modules/,loader:'jshint-loader' + // } + ], + loaders: [ + // 加载vue组件,并将css全部整合到一个style.css里面 + // 但是使用这种方式后 原先可以在vue组件中 在style里面加入 scoped 就不能用了, + // 好处是使用了cssnext,那么样式按照标准的来写就行了,会自动生成兼容代码 http://cssnext.io/playground/ + { + test: /\.vue$/, + loader: 'vue' + }, + {test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader?sourceMap!cssnext-loader")}, + {test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'}, // 内联 base64 URLs, 限定 <=8k 的图片, 其他的用 URL + {test: /\.woff$/, loader: "url?limit=10000&minetype=application/font-woff"}, + {test: /\.ttf$/, loader: "file"}, + {test: /\.eot$/, loader: "file"}, + {test: /\.svg$/, loader: "file"} + ] + }, + vue:{ + css:ExtractTextPlugin.extract("style-loader", "css-loader?sourceMap!cssnext-loader") + }, + plugins : plugins, + devtool: 'source-map'//, + // resolve: { + // // 现在可以写 require('file') 代替 require('file.coffee') + // extensions: ['', '.js', '.json', '.coffee','vue'] + // } +}; + + diff --git a/约定.md b/约定.md new file mode 100644 index 0000000..bf3f796 --- /dev/null +++ b/约定.md @@ -0,0 +1,144 @@ + + +#### 使用具名路径 + +``` +User +``` + +#### 组件传值的时候单个单词小写,如果有多个单词用"-"连接 [API说明](http://rc.vuejs.org/guide/components.html#camelCase_vs-_kebab-case) + +``` + + +``` +然后在组件props中用驼峰的方式访问['mutilCheck']。 + +#### 组件传值得时候尽量不要使用表达式,可以在computed中定义 +比如: + +``` + +``` +修改为 +``` + +``` +然后定义computed + +``` + ... + computed:{ + singleCheck:function(){ + return false; + } + }, + ... +``` + +#### 在绑定属性的时候 +``` +
+ +
+ 此处的 transition="transiton" 代表的是 transition 这个类名 +``` +而如果前面加个`:`则代表的是动态属性,: 是 v-bind的简写 参考 [Vue1.0.0绑定语法参考](https://github.com/vuejs/vue/issues/1325) + +``` +
+``` + +#### 绑定属性用双引号 + + +#### 关于 vueComponent.sublime-snippet 文件 +``` +功能:sublime中编写vue组件的片段提示 +使用: + sublime中 菜单栏 - >Preferences - > 浏览插件 + 将文件复制到 User目录下 + 项目中新建 `组件名字.vue` 文件 + ctrl+shift+p 输入 vuecomponent 回车 +``` + + +#### 在vue组件 template 中不能出现 `<` 字符, 如果有此字符,那么在使用webpack.optimize.UglifyJsPlugin压缩的时候,编译会报错 + +#### DOM属性定义用""包起来,否则不正确的字符可能会导致在 使用webpack.optimize.UglifyJsPlugin压缩的时候,控制台卡死。 + +#### vue文件的,template模版中,注释的html里面如果有img标签,相关资源也会被打包。 + +``` + + +``` + +#### 在data属性里面不要定义以下划线开头的字段。 + +``` +data:{ + _k:'v' // this._k 获取不到 +} +``` + +#### vue-router路由配置的时候,不要写下划线 + +``` + '/loan':{ + name:'loan', + component: require('./views/loan.vue') + }, + '/loan_old':{ + name:'xxx', + component: require('./views/loan_old.vue') + }, + 下面的会覆盖上面的,原来本应该跳转到loan的可能现在都跳到了loan_old +``` + +#### 关于版本控制 +参考: +[http://webpack.github.io/docs/long-term-caching.html](http://webpack.github.io/docs/long-term-caching.html) + +[https://github.com/teambition/coffee-webpack-starter/blob/92082085d96f6c5003711e042da38bfa140d8dd6/webpack.min.coffee#L21](https://github.com/teambition/coffee-webpack-starter/blob/92082085d96f6c5003711e042da38bfa140d8dd6/webpack.min.coffee#L21) + + +``` + plugins: [ + new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.[chunkhash:8].js'), + new webpack.optimize.UglifyJsPlugin({sourceMap: false}), + new ExtractTextPlugin("style.[chunkhash:8].css"), + function() { + return this.plugin('done', function(stats) { + var content; + content = JSON.stringify(stats.toJson().assetsByChunkName, null, 2); + return fs.writeFileSync('build/assets.json', content); + }); + } + ] +``` + +#### 禁止在层上滑动(比如:背景层,不想让用户滚动) +``` +@touchstart.stop.prevent +``` + +#### 如果要阻止默认事件,一定要写在前面,否则会影响其他事件绑定 +``` +@touchmove.stop.prevent @click.stop="show=false" +``` + +#### 尽量少用