【发布时间】:2021-01-21 04:05:48
【问题描述】:
我对我的 Vue 组件中的代码感到非常困惑,因为任何元素都应用来自 {{ title }} 的模板,除了一个仅将模板语法显示为纯 HTML 的 按钮。
我的代码:
<template>
<li>
<h2>{{ friend.name }}</h2>
<!-- this button has the {{ title }} in it, but vue wont render it when generating the page -->
<button>{{ title }}</button>
<!-- this p-tag on the other hand got the same syntax template and works just fint -->
<p>{{ title }}</p>
<ul v-if="detailsAreVisible">
<li><strong>Phone: </strong>{{ friend.phone }}</li>
<li><strong>Email: </strong>{{ friend.email }}</li>
</ul>
</li>
</template>
<script>
export default {
data() {
return {
//this the string that should be inside the button
title: "HELLO",
detailsAreVisible: false,
friend: {
id: "max",
name: "Max Musterman",
phone: "0151 2548 425",
email: "max@localhost.de",
},
};
},
methods: {
toggleDetails() {
this.detailsAreVisible = !this.detailsAreVisible;
},
},
computed: {
toggleButtonText() {
let innerText = this.detailsAreVisible ? "Hide" : "Show";
return innerText + " Details";
},
},
};
</script>
【问题讨论】:
标签: javascript html vue.js components vue-component