add refs example

This commit is contained in:
Andreas Zweili 2021-01-23 09:53:15 +01:00
parent 10a51af597
commit 83c735ea33
2 changed files with 27 additions and 26 deletions

View File

@ -1,18 +1,19 @@
const app = Vue.createApp({ const app = Vue.createApp({
data() { data() {
return { return {
currentUserInput: '', currentUserInput: "",
message: 'Vue is great!', message: "Vue is great!",
}; };
},
methods: {
saveInput(event) {
this.currentUserInput = event.target.value;
}, },
setText() { methods: {
this.message = this.currentUserInput; saveInput(event) {
this.currentUserInput = event.target.value;
},
setText() {
//this.message = this.currentUserInput;
this.message = this.$refs.userText;
},
}, },
},
}); });
app.mount('#app'); app.mount("#app");

View File

@ -1,26 +1,26 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue Basics</title> <title>Vue Basics</title>
<link <link href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap" rel="stylesheet" />
href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="styles.css" /> <link rel="stylesheet" href="styles.css" />
<script src="https://unpkg.com/vue@next" defer></script> <script src="https://unpkg.com/vue@next" defer></script>
<script src="app.js" defer></script> <script src="app.js" defer></script>
</head> </head>
<body>
<body>
<header> <header>
<h1>Vue Behind The Scenes</h1> <h1>Vue Behind The Scenes</h1>
</header> </header>
<section id="app"> <section id="app">
<h2>How Vue Works</h2> <h2>How Vue Works</h2>
<input type="text" @input="saveInput"> <input type="text" ref="userText">
<button @click="setText">Set Text</button> <button @click="setText">Set Text</button>
<p>{{ message }}</p> <p>{{ message }}</p>
</section> </section>
</body> </body>
</html> </html>