vue学习笔记

index.html — main.js(index.js) — App.vue — router.js — components

router路由:根据不同的url地址跳到不同的组件
hello.vue组件:组件就是包含html+script+css的单独的页面,也可以叫做单独的功能模块

 

下载项目:
上github.com搜索项目
在终端下载:git clone https://github.com/itemsets/vue2

 

@常用命令
cd 进入目录
ls 显示文件
vr 运行项目

@新建vue项目
cd /home/bkd/workspace/vue;
vue init webpack firstProject;
事件:v-on:click,@click
属性:v-bind:message,:message
文本:{{ message }}
数组:v-for = “item in list”
提示信息:title属性
定义vue变量:
var app = new Vue({
el: ‘#app’,
data: {
message: ‘页面加载于 ‘ + new Date().toLocaleString()
},
methods : {
click1: function(){
alert(this.message)
}
}

})

vue路由:
import Vue from ‘vue’;
import Router from ‘vue-router’;

Vue.use(Router);

export default new Router({

routes: [
{
path: ‘/’,
component: resolve => require([‘../components/home/home.vue’], resolve),
children: [
{
path: ‘/index’,
component: resolve => require([‘../components/index/index.vue’], resolve)
},
{
path: ‘/contents’,
component: resolve => require([‘../components/item/item.vue’], resolve)
},
{
path: ‘*’,
component: resolve => require([‘../components/index/index.vue’], resolve)
}
]
}

 

]
})

—-路由2
export default [{
path: ‘/’,
component: App,
children: [{
path: ”,
component: r => require.ensure([], () => r(require(‘../page/home’)), ‘home’)
}, {
path: ‘/item’,
component: r => require.ensure([], () => r(require(‘../page/item’)), ‘item’)
}, {
path: ‘/score’,
component: r => require.ensure([], () => r(require(‘../page/score’)), ‘score’)
}]
}]

Author: bkdwei