-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vue 知识点及问题汇总 #7
Comments
模拟已废弃 vue 1.x 的
|
vue 组件使用 父组件 <template>
<div>
<Child v-model="list" />
</div>
</template>
<script>
import Child from './Child'
export default {
name: 'Parent',
component: { Child },
data () { return { list: [1,2,3] } }
}
</script> 子组件 <template>
<div class="child" @click="newList">
<img v-for="item in list" />
</div>
</template>
<script>
export default {
name: 'Child',
model: {
prop: 'list',
event: 'new'
},
methods: {
newList () {
this.$emit('new', [4, 5, 6])
}
}
}
</script> |
computed 属性绑定过程如官方给的例子 var vm = new Vue({
el: '#example',
data: {
message: 'Hello'
},
computed: {
// 计算属性的 getter
reversedMessage: function () {
// `this` 指向 vm 实例
return this.message.split('').reverse().join('')
}
}
})
|
Open
ivew 组件 Tabs 第一次切换标签内部 Table 卡顿问题 <Tabs>
<TabPane label="折线图" name="line-chart">
<SimpleChart :data="data" />
</TabPane>
<TabPane label="表格" name="table">
<SimpleGrid :data="data" :columns="columns" />
</TabPane>
</Tabs> 分析:进到 Modal 时,折线图和表格组件都已经渲染,但此时表格的 TabPane display:none,Table 获取不到宽高,所以渲染出来的数据堆在一条线上。当切换到表格时,display:block,Table 获取宽高撑开盒子,所以有了一瞬间的卡顿。 解决方法:使用 this.$nextTick 控制表格延迟渲染 <Tabs @on-click="onTabClick">
<TabPane label="折线图" name="line-chart">
<SimpleChart :data="data" />
</TabPane>
<TabPane label="表格" name="table">
<SimpleGrid :data="data" :columns="columns" v-if="mount" />
</TabPane>
</Tabs> export default {
...
data () {
return {
mount: false
}
},
methods: {
onTabClick (name) {
if (name === 'table') {
this.$nextTick(() => {
this.clickTable = true
})
}
}
}
...
} |
程序化的事件侦听器例如,你可能经常看到这种集成一个第三方库的模式: // 一次性将这个日期选择器附加到一个输入框上
// 它会被挂载到 DOM 上。
mounted: function () {
// Pikaday 是一个第三方日期选择器的库
this.picker = new Pikaday({
field: this.$refs.input,
format: 'YYYY-MM-DD'
})
},
// 在组件被销毁之前,
// 也销毁这个日期选择器。
beforeDestroy: function () {
this.picker.destroy()
} 这里有两个潜在的问题:
你应该通过一个程序化的侦听器解决这两个问题: mounted: function () {
var picker = new Pikaday({
field: this.$refs.input,
format: 'YYYY-MM-DD'
})
this.$once('hook:beforeDestroy', function () {
picker.destroy()
})
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
关于vue
The text was updated successfully, but these errors were encountered: