初涉vue就深深的被vue强大的功能,快速的开发能力所折服。所以就写了一个cnode社区的app来实践对vue的学习成果。也算是入坑指南吧,如果您觉得对您有帮助,就在github上给个star吧,代码拙劣,大神请忽略。。。
node -v
npm -v
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g vue-cli
vue init webpack basic-functions("basic-functions"为自己的项目名称)
cd basic-functions '(进入项目文件夹)'
cnpm install '(下载依赖包)'
npm run dev '(启动项目,一定要在有package.json的当前目录运行)'
--- build '(webpack配置文件)'
--- config '(开发及生产环境配置)'
--- nodele_modules '(npm install 现在下来的依赖包)'
--- src ('开发目录)'
|--- assets '(资源文件夹-js,vue,img,css等)'
|--- router '(路由文件)'
|--- index.js'(控制路由跳转页面)'
|--- App.vue '(App.vue组件)'
|--- main.js '(预编译入口)'
--- static '(静态资源文件)'
--- .babelrc '(babel配置文件)'
--- .gitignore '(git提交忽略规则')
--- index.html '(主页)'
--- package.json '(项目配置文件)'
--- README.md
cnpm install less-loader --save-dev
cnpm install node-less --save-dev
<script>
import './src/style/base.less'
</script>
cnpm install webpack-zepto --save-dev
new webpack.ProvidePlugin({
$: "webpack-zepto",
Zepto: "webpack-zepto",
"window.Zepto": "webpack-zepto"
})
(./App.vue)
export default {
mounted:function() {
console.log($('img').length)
}
}
import Vue from 'vue'
import App from './App'
import router from './router'
import $ from 'webpack-zepto'
import filter from './utils/filter.js';
//注册全局组件
Vue.prototype.$filter = filter;
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/page/index'
import Topic from '@/page/topic'
import PublishTopic from '@/page/publishTopic'
import Login from '@/page/login'
import User from '@/page/user'
import Message from '@/page/message'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
redirect: {name: 'index'}
},
{
path: '/',
name: 'index',
component: Index
},
{
path: '/topic/:id',
name: 'topic',
component: Topic
},
{
path: '/create',
name: 'create',
component: PublishTopic,
meta: { requiresAuth: true }
},
{
path: '/login',
name: 'login',
component: Login
},
{
path: '/user/:loginname',
name: 'user',
component: User
},
{
path: '/message',
name: 'message',
component: Message,
meta: { requiresAuth: true }
}
]
})
本文为 @ 21CTO 创作并授权 21CTO 发布,未经许可,请勿转载。
内容授权事宜请您联系 webmaster@21cto.com或关注 21CTO 公众号。
该文观点仅代表作者本人,21CTO 平台仅提供信息存储空间服务。