gpt4 book ai didi

vuejs2 - VueJS : @click. native.stop = ""可能吗?

转载 作者:行者123 更新时间:2023-12-03 23:17:04 25 4
gpt4 key购买 nike

我在页面上有几个嵌套组件,其父组件具有 @click.native执行。因此,当我单击子组件(位于父组件内)占据的区域时,执行的两个单击操作(父组件和所有嵌套的子组件)例如

<products>
<product-details>
<slide-show>
<media-manager>
<modal-dialog>
<product-details>
<slide-show>
<media-manager>
<modal-dialog>
</products>

所以我有多个产品的列表,当我点击属于模态对话框的“ Canvas ”时 - 我也得到 @click.native在模态对话框所属的产品详细信息上触发。如果有类似 @click.native.stop="code" 的东西就好了, 这可能吗?

现在我必须这样做:
@click.native="clickHandler"
and then

methods: {
clickHandler(e) {
e.stopPropagation();
console.log(e);
}

代码
<template>
<div class="media-manager">
<div v-if="!getMedia">
<h1>When you're ready please upload a new image</h1>
<a href="#"
class="btn btn--diagonal btn--orange"
@click="upload=true">Upload Here</a>
</div>
<img :src="getMedia.media_url"
@click="upload=true"
v-if="getMedia">
<br>
<a class="arrow-btn"
@click="upload=true"
v-if="getMedia">Add more images</a>
<!-- use the modal component, pass in the prop -->
<ModalDialog
v-if="upload"
@click.native="clickHandler"
@close="upload=false">
<h3 slot="header">Upload Images</h3>
<p slot="body">Hello World</p>
</ModalDialog>
</div>
</template>

<script>
import ModalDialog from '@/components/common/ModalDialog';
export default {
components: {
ModalDialog,
},
props: {
files: {
default: () => [],
type: Array,
},
},
data() {
return {
upload: false,
}
},
computed: {
/**
* Obtain single image from the media array
*/
getMedia() {
const [
media,
] = this.files;

return media;
},
},
methods: {
clickHandler(e) {
e.stopPropagation();
console.log(e);
}
}
};
</script>

<style lang="scss" scoped>
.media-manager img {
max-width: 100%;
height: auto;
}

a {
cursor: pointer;
}

</style>

最佳答案

你看说明书了吗? https://vuejs.org/v2/guide/events.html

@click.stop=""@click.stop.prevent=""
所以你不需要使用这个

methods: {
clickHandler(e) {
e.stopPropagation();
console.log(e);
}
}

关于vuejs2 - VueJS : @click. native.stop = ""可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49041779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com