很久没上传笔记了,主要最近的笔记都零零散散,知识点也不集中,就不传了;最近项目想用到先后端分离,并且前端我也想参与下,就先基本的学一遍,记点零星的笔记,各位能从中看到有用的东西最好css
nodejs.cn
中文文档地址var http = require("http")引入模块 http.createServer(function(request,response){ response.writeHead(200,{'Content-Type':'text/plain'}); resposne.end('Hello world!'); }).listen(8888); cmd运行`node demo4` 制做模块 exports.add=function(x,y){ return x+y; }
npm init
初始化工程,生成package.json,至关于maven中pomnpm install express
安装模块express
npm root -g
显示全局目录npm install jquery -g
,全局安装package.json
时,须要npm install
下载对应的node_modules
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm -v
查看版本cnpm install
须要下载的js库npm run dev
npm run build
cnpm install webpack -g
全局安装cnpm install webpack-cli -g
命令包webpack -v
查看是否安装完毕,安装版本webpack
cnpm install style-loader css-loader --save-dev
https://code.visualstudio.com
vetur
,HTML Snippets
,HTML CSS Support
,Debugger for Chrome
,VueHelper
var
是全局的,let
做用域局部的const
,常量不可变let name = "bac";console.log('hello, ${name}')
function action(num = 200){ console.log(num) } action(); action(100);
function add(a,b){ return a+b; } console.log(add(100,200)); //ES6 add = (a,b) => { return a+b; } add = (a,b) => a+b;
// ES5 function people(name ,age){ return { name:name, age: age } } //ES6 function people(name, age){ return { name, age } }
//ES5 const people= { return { name:name, age: age } } const name = people.name; const age = people.age; //ES6 const {name ,age} = people; console.log(name); console.log(age);
const color = ['red','green']; const colorful =[...color,'pink']; const people = {name:'xyx',age:20}; const peopleful = {...people,address:'aaaa'}
let fn0=function(){ console.log('fne...'); } export {fn0}
//从某个js文件中导入某个模块 import {fn0} from './lib'
node8 不支持import,能够用require,不用import,或者用babel
的命令行工具来执行前端
cnpm install
,npm run dev
build
构建目录,构建的相关配置config
配置目录,须要修改config/dev.env.js
中的mock路径,此处测试能够用easyMock,生产则改config/prod.env.js
node_modules
经过cnpm install
安装的依赖,不用本身写src
主要的编写目录
src/api
编写请求接口的封装src/assets
静态资源管理src/router
路由信息src/store
存储全局信息方法src/styles
样式信息src/utils
工具方法src/views
视图信息,须要着重修改的地方src/App.vue
全局视图基本框架src/main.js
主入口,实例化Vuepackage.json
打包文件,通常不用修改template
中,<router-view/>
用来代表须要路由的标签区域<router-link to="/" >首页</router-link>
表示路由链接地址,链接到另外一个模板import Vue from 'vue' import Router from 'vue-router' import HelloWorld from '@/components/HelloWorld' import List from '@/components/list' import Item from '@/components/item' Vue.use(Router) export default new Router({ routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path: '/list', name: 'List', component: List }, { path: '/item/:id', name: 'Item', component: Item } ] })
# 建立一个基于 webpack 模板的新项目 vue init webpack vuexdemo # 安装依赖,走你 cd vuexdemo cnpm install --save vuex npm run dev
import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vuex.Store({ state: { count: 0 } }) export default store
import Vue from 'vue' import App from './App' import router from './router' import store from './store' Vue.config.productionTip = false new Vue({ el: '#app', router, store, components: { App }, template: '<App/>' })
const store = new Vuex.Store({ state: { count: 0 }, mutations: { increment(state){ state.count++ } } })
this.$store.commit('increment')
mutations: { increment (state,x) { state.count += x } }
this.$store.commit('increment',10)
mutation
,能够包含任意异步操做mutations: { increment(state,x){ state.count+=x } }, actions: { increment(context,x){ context.commit('increment',x) } }
this.$store.dispatch('increment')
因此vue
key | 方法 |
---|---|
mutations | $store.commit('increment') |
actions | $store.dispatch('increment') |
{{$store.getters.remark}}
getters: { remark(s){ if(s.count<50){ return '加油' }else if(s.count<100){ return '你真棒' }else{ return '你是大神' } } }
...
,好比item是一个对象,下列表示item中加了个属性count{ ...item, count:0 }