好久没上传笔记了,主要最近的笔记都零零散散,知识点也不集中,就不传了;最近项目想用到前后端分离,而且前端我也想参与下,就先基本的学一遍,记点零星的笔记,各位能从中看到有用的东西最好
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')
所以
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
}