我收到了很多这样的帖子:
<template>
<div id="posts">
<div id="posts-wrapper">
<post v-for="(item, key) in posts" :key="item.id" :post="item" :isListItem="true"></post>
</div>
<infinite-loading :on-infinite="onInfinite" ref="infiniteLoading">
<span slot="no-more">
There are no more posts
</span>
</infinite-loading>
</div>
</template>
<script>
import InfiniteLoading from 'vue-infinite-loading'
import posts from '@/api/posts'
import post from '@/components/Post'
export default {
name: 'posts',
components: {
post,
InfiniteLoading,
},
data () {
return {
posts: []
}
},
methods: {
onInfinite() {
posts.getPosts(page++).then(posts => {
this.posts = this.posts.concat(posts);
this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
})
}
}
};
</script>
这是post
组件:
<template>
<v-card class="post-list-item" v-bind:class="{ clickable: isListItem }" @click.native="openPost">
<div class="header">
{{ post.name }}
</div>
<div class="image">
</div>
<div class="data">
</div>
<!-- same handler bound here just for testing -->
<div class="button" v-on:click.native="openPost">
Open post
</div>
</v-card>
</template>
<script>
export default {
name: 'post',
methods: {
openPost() {
console.log('post opening');
}
},
props: {
post: {
type: Object,
required: true
},
isListItem: {
type: Boolean,
default: false
}
},
data () {
return {}
}
}
</script>
问题是点击不会通过,即。永远不会调用openPost()
方法。如果我在父母中设置一个监听器,那么这是有效的,但不是我正在寻找的。点击应该在组件本身内处理。
v-card
是Vuetify component。
我做错了什么?
答案 0 :(得分:0)
我遇到了同样的问题,但我使用
解决了这个问题v-on:click
而不是
@click.native