commit | author | age
|
5978c3
|
1 |
const app = Vue.createApp({ |
CM |
2 |
data() { |
|
3 |
return { |
|
4 |
currentUserInput: '', |
|
5 |
message: 'Vue is great!', |
|
6 |
}; |
|
7 |
}, |
|
8 |
methods: { |
|
9 |
saveInput(event) { |
|
10 |
this.currentUserInput = event.target.value; |
|
11 |
}, |
|
12 |
setText() { |
|
13 |
// this.message = this.currentUserInput; |
|
14 |
this.message = this.$refs.userText.value; |
|
15 |
// console.dir(this.$refs.userText); |
|
16 |
}, |
|
17 |
}, |
|
18 |
}); |
|
19 |
|
|
20 |
app.mount('#app'); |
|
21 |
|
|
22 |
const app2 = Vue.createApp({ |
|
23 |
template: ` |
|
24 |
<p>{{ favoriteMeal }}</p> |
|
25 |
`, |
|
26 |
data() { |
|
27 |
return { |
|
28 |
favoriteMeal: 'Pizza' |
|
29 |
}; |
|
30 |
} |
|
31 |
}); |
|
32 |
|
|
33 |
app2.mount('#app2'); |
|
34 |
|
|
35 |
// .... |
|
36 |
|
|
37 |
const data = { |
|
38 |
message: 'Hello!', |
|
39 |
longMessage: 'Hello! World!' |
|
40 |
}; |
|
41 |
|
|
42 |
const handler = { |
|
43 |
set(target, key, value) { |
|
44 |
if (key === 'message') { |
|
45 |
target.longMessage = value + ' World!'; |
|
46 |
} |
|
47 |
target.message = value; |
|
48 |
} |
|
49 |
}; |
|
50 |
|
|
51 |
const proxy = new Proxy(data, handler); |
|
52 |
|
|
53 |
proxy.message = 'Hello!!!!'; |
|
54 |
|
|
55 |
console.log(proxy.longMessage); |