【发布时间】:2020-06-13 16:29:03
【问题描述】:
我从几天前开始学习 Vue.JS,我只是在尝试做一个在点击按钮时添加芯片的应用程序。创建的芯片应该将输入的值作为名称。 我创建了一个(通常)应该创建这个芯片的方法。它甚至没有调用方法,我不知道为什么,我试图在方法的开头 console.log 一些东西来检查它......
谢谢大家!
我的 App.vue:
<template>
<v-app id="whole_container">
<v-content id="main_container">
<v-row id="main_row">
<v-col class="hellocol" id="chips">
<customChip name="Louis"></customChip>
</v-col>
<v-col class="hellocol" id="chipField">
<addChip></addChip>
</v-col>
</v-row>
</v-content>
</v-app>
</template>
<script>
import customChip from './components/chip.vue';
import addChip from './components/addChip.vue';
export default {
name: 'App',
components: {
customChip,
addChip
},
data: () => ({
//
}),
};
</script>
我的 AddChip 文件:
<template>
<div>
<v-text-field id="newChip" :outlined="true" label="Entrez un nom" placeholder="Michel" v-model="currentName"></v-text-field>
<p>Je m'appelle {{ currentName }}</p>
<chipButton @click="addChip( currentName )"></chipButton>
</div>
</template>
<script>
import chipButton from './button.vue';
export default {
data: () => ({
currentName: ""
}),
components: {
chipButton,
},
methods: {
addChip: function(name) {
console.log(name);
let actualChips = document.getElementById('chips');
let newChip = document.createElement('customChip');
newChip.name = name;
actualChips.appendChild('newChip');
}
}
}
</script>
【问题讨论】:
标签: javascript vue.js