还把const app修改成export default {
<template>
<title>陈尼克</title>
<div id="app" v-cloak>
<p>姓名: {{ name }}</p>
<p>职业: {{ state.work }}</p>
</div>
</template>
<script>
import { ref, reactive } from 'vue'
export default {
setup() {
const name = ref("Nick")
const state = reactive({
work: "前端工程师",
});
return {
state,
name,
};
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
下面修改一下他的工作
不对
<template>
<title>陈尼克</title>
<div id="app" v-cloak>
<p>姓名: {{ name }}</p>
<p>职业: {{ state.work }}</p>
</div>
</template>
<script>
import { ref, reactive } from 'vue'
export default {
setup() {
const name = ref("Nick")
const state = reactive({
work: "前端工程师",
}),
const state.work.value = "摄影师";
return {
state,
name,
};
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
加了一个年龄
<template>
<title>陈尼克</title>
<div>
<p>姓名: {{ name }}</p>
<p>职业: {{ state.work }}</p>
<p>年龄: {{ state.age }}</p>
</div>
</template>
<script>
import { ref, reactive } from 'vue'
export default {
setup() {
const name = ref("Nick")
const state = reactive({
work: "前端工程师",
age: "18",
});
return {
state,
name,
};
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>