A Vue.js project
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev或者npm start
# build for production with minification
npm run build
# run unit tests
npm run unit
# run e2e tests
npm run e2e
# run all tests
npm test
For detailed explanation on how things work, checkout the guide and docs for vue-loader. and vue中文文档 and vue-router
data(){}
放置变量ready(){}
当页面加载完成去请求computed:{}
动态计算动态改变的值route:{}
设置路由的钩子函数components:{}
放置组件methods:{}
放置方法props:{} | []
获取父组件的数据
使用 props
传递数据时,要在使用子组件的地方绑定一下,然后在子组件的模版里才能使用
如果不想用 props
,也可以在子组件里用 this.$parent.父组件名
来获取
this.$parent
访问父组件this.$root
访问跟实例this.$children
访问子元素
- 使用
$on()
监听事件 - 使用
$emit()
在它上面触发事件 - 使用
$dispatch()
派发事件,时间沿着父链冒泡
子组件派发事件,父组件用 event
接收或者用 v-on
监听
- 使用
$broadcast()
广播事件,事件向下传导给所有的后代 - 定义
v-ref
可以在js
里直接访问子组件