{{msg}}
v-html=""
v-bind:id=""
{{ ok?'Yes:No' }}
v-text=""
v-if=""
条件判断{{ message | capitalize }}
和v-bind:id="rawId | formatId"
v-bind:class="{'active':isActive, 'text-danger':hasError}"
v-bind:class="[activeClass, errorClass]"
data:{
activeClass:'active',
errorClass:'text-danger'
}
v-bind:style=""
v-if
v-else
v-else-if
v-show
v-cloak
v-if
如果条件不成立,元素不渲染
v-show
如果条件不成立,渲染,置display:none
v-cloak
如果页面刷新的太快,导致有些页面的元素没有加载出来,v-cloak
可以同步隐藏html代码
v-on:click="greet"
或 @click="greet"
v-on:click.stop
阻止事件冒泡 v-on:click.stop.prevent
阻止默认事件 v-on:click.self
给这个div绑定事件的对象本身绑定事件? v-on:click.once
给这个事件绑定一次v-on:keyup.enter
import HelloWorld from '@/components/HelloWorld'
@ 表示 src 目录
配置路由的index.js
中的路由模式mode
mode:'hash'
哈希模式。url中带#,例如 http://localhost:8888/#/goods/4556/user/admin
mode:'history'
浏览器的history模式。url中没有#,例如 http://localhost:8888/goods/4556/user/admin
嵌套路由
路由index.js
import Vue from 'vue'
import Router from 'vue-router'
import GoodsList from '@/views/GoodsList'
import Title from '@/views/Title'
Vue.use(Router)
export default new Router({
mode: 'history',
routes: [{
path: '/goods',
name: 'GoodsList',
component: GoodsList,
children: [{
path: 'title',
name: 'title',
component: Title
}]
}]
})
views/GoodsList.vue
<template>
<div>
<p>这是商品列表页p>
<router-link to="/goods/title">标题router-link>
<div>
<router-view>router-view>
div>
div>
template>
<style>
style>
<script>
export default {
data() {}
}
script>
views/Title.vue
<template>
<div>
<p>这是商品标题组件p>
div>
template>
<style>
style>
<script>
export default {
data() {}
}
script>
编程路由
通过js来实现页面的跳转
$router.push("name")
$router.push({path:"name"})
$router.push({path:"name?a=1234"})或$router.push({path:"name",query:{a:1234}})
… …
define(['package/lab'],function(lab){
function foo(){
console.log("hello world")
}
return {
foo:foo
};
});
define(function(require, exports, module){
var $ = require("jquery")
var Spinning = require("./spinning")
});
exports.area = function (r) {
return Math.PI * r * r;
};
exports.circumference = function (r) {
return 2 * Math.PI * r;
};
export default {
name: 'HelloWorld',
data () {
return {
num:10,
msg: 'Welcome to Your Vue.js App'
}
},
methods:{
increment () {
this.num++;
},
decrement () {
this.num--;
}
},
components:{
Counter
}
}
express的router通过get与POST传递参数时,后端获取参数的方式的区别
req.param("param1")
的方式获取req.body.param1
的方式获取前端传参的区别
axios.get('/path',{
params:{
key:value
}
}).then((res)=>{
});
axios.post('/path',{
key:value
}).then((res)=>{
});
是
var param = {
userName: req.body.userName,
userPwd: req.body.userPwd
}
不是
var param = {
userName = req.body.userName,
userPwd = req.body.userPwd
}
(req, res, next)
,不是(res, req, next)
很明显了,错误信息都给出了 cmd
关键词,我一开始一直以为是node的版本的问题,特地把版本降到了7.0,错误的参考了github上关于这个问题的讨论 升级Node.js 8 之后,npm run dev 会出现问题
为此我还学会了如何卸载高版本的node,再装回旧版本的。要卸载高版本的node,有一个办法就是再重新点开这个版本的node安装包,在安装选项中选择remove
就可以卸载当前的node版本了,之后再装其他低版本的node就都没问题了
浪费了我很多时间,最后终于找到了解决办法 Get ‘spawn cmd ENOENT’ when try to build Cordova application (event.js:85) 我按照链接里的方法将C:\Windows\System32
添加到环境变量path
中就好了,点赞量高的答案果然很有用!
专门为vue.js应用程序开发的状态管理模式
构建中大型单页面程序时,Vuex能够更好的帮助我们在组件外部统一管理状态
核心概念
State 唯一的数据源、载体
Getters 通过getters可以派生出一些新的状态
Mutations 唯一可以提交和改变状态的,Vuex的store中的状态的唯一提交方法
Actions 提交的是mutation,而不是直接变更的状态,可以包含任意异步操作
Modules 面对复杂的应用程序,当管理的状态比较多时,需要将Vuex的store对象分割成模块(modules)
后端和前端代码分开。使用nginx实现接口转发,不会跨域
部署到线上时如果采用文件夹的形式,注意修改路径配置config/index.js/
中的assetsPublicPath
为代码存放的文件夹,否则会找不到资源文件的路径
课程资源下载链接