(个人记录)
必要
命名
- 组件名必写
- 组件名为多个单词
- 组件名为大驼峰
export default {
name: 'TodoItem',
// ...
}
组件数据
- data必须是函数
export default {
data () {
return {
foo: 'bar'
}
}
}
Prop定义
- 尽可能详细,写出类型和默认值
props: {
status: {
type: String,
default: 'syncing'
}
}
key值
- 在使用v-for时,必须写key值
- 尽可能使用后台主键或唯一值作为key
- 实在没办法选择使用index
<ul>
<li v-for="todo in todos"
:key="todo.id"