【发布时间】:2021-05-23 16:11:08
【问题描述】:
所以在我学习 vue 时,我想仔细检查是否有人可以告诉我我做错了什么或引导我找到正确的答案。下面,我将展示代码,然后解释我正在尝试做的事情。
这是我的Vue.js 应用程序:
Vue.component('o365_apps_notifications', {
template:
`
<div class="notification is-success is-light">
// Call the name here and if added/removed.
</div>
`,
});
new Vue({
name: 'o365-edit-modal',
el: '#o365-modal-edit',
components: 'o365_apps_notifications',
data() {
return {
list: {},
movable: true,
editable: true,
isDragging: false,
delayedDragging: false,
options: {
group: 'o365apps',
disabled: true,
handle: '.o365_app_handle',
}
}
},
methods: {
add(index, obj) {
console.log(obj.name);
this.$data.list.selected.push(...this.$data.list.available.splice(index, 1));
this.changed();
},
remove(index, obj) {
console.log(obj.name);
this.$data.list.available.push(...this.$data.list.selected.splice(index, 1));
this.changed();
},
checkMove(evt) {
console.log(evt.draggedContext.element.name);
},
},
});
这是我的模态:
<div id="o365-modal-edit" class="modal">
<div class="modal-background"></div>
<div class="modal-card px-4">
<header class="modal-card-head">
<p class="modal-card-title">Applications</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body">
<div class="container">
<div id="o365-modal-edit-wrapper">
<div class="columns">
<div class="column is-half-desktop is-full-mobile buttons">
// Empty
</div>
<div class="column is-half-desktop is-full-mobile buttons">
// Empty
</div>
</div>
</div>
</div>
</section>
<footer class="modal-card-foot">
<o365-apps-notifications></o365-apps-notifications>
</footer>
</div>
</div>
这是我正在尝试做的事情:
在我的模式中,我调用了我的o365_apps_notifications html 标记,我的add() 和remove() 方法使用console.log(obj.name); 在每次添加/删除时输出一个名称,我的checkMove 方法也将相同的名称拖到如下图拖动:
-
如何让我的组件在模态页脚中呈现和输出名称?我已经尝试了所有方法,但我似乎无法弄清楚如何触发组件。
-
另外,我是否必须做一些特别的事情才能使组件在设定的时间范围后淡出?
感谢所有帮助!
【问题讨论】:
-
您需要在通知组件上定义一个道具。与其写入控制台,不如将名称存储在变量中,并将其链接到通知组件上的 prop。请查看 Vue 文档以了解这一点,在进行 Vue 编程时理解这一点至关重要。
标签: javascript vue.js vuejs2