<!DOCTYPE html>
<div id="computed-basics">
<p>His published books:</p>
<span>{{ author.books.length > 2 ? 'Yes' :'No' }}</span>
</div>
</html>
<script src="https://unpkg.com/vue@next"></script>
<script>
Vue.createApp({
data() {
return {
author: {
name: 'John Doe',
books: [
'Vue 2 - Advance Guide',
'Vue 3 - Basic Guide',
'Vue 4 - The Mystery'
]
}
}
},
computed: {
publishedBooksMessage() {
return this.author.books.length > 0 ? 'Yes' : 'No'
}
}
}).mount('#computed-basics')
</script>
2可以改成0或3、4
<!DOCTYPE html>
<div id="computed-basics">
<p>His published books:</p>
<span>{{ author.books.length > 0 ? 'Yes' :'No' }}</span>
</div>
</html>
<script src="https://unpkg.com/vue@next"></script>
<script>
Vue.createApp({
data() {
return {
author: {
name: 'John Doe',
books: [
'Vue 2 - Advance Guide',
'Vue 3 - Basic Guide',
'Vue 4 - The Mystery'
]
}
}
},
computed: {
publishedBooksMessage() {
return this.author.books.length > 0 ? 'Yes' : 'No'
}
}
}).mount('#computed-basics')
</script>
他出版了几本书
<!DOCTYPE html>
<div id="computed-basics">
<p>His published books:</p>
<span>{{ author.books.length }}</span>
</div>
</html>
<script src="https://unpkg.com/vue@next"></script>
<script>
Vue.createApp({
data() {
return {
author: {
name: 'John Doe',
books: [
'Vue 2 - Advance Guide',
'Vue 3 - Basic Guide',
'Vue 4 - The Mystery'
]
}
}
},
computed: {
publishedBooksMessage() {
return this.author.books.length > 0 ? 'Yes' : 'No'
}
}
}).mount('#computed-basics')
</script>
第四个
<!DOCTYPE html>
<div id="computed-basics">
<p>His published books:</p>
<span>{{ publishedBooksMessage }}</span>
</div>
</html>
<script src="https://unpkg.com/vue@next"></script>
<script>
Vue.createApp({
data() {
return {
author: {
name: 'John Doe',
books: [
'Vue 2 - Advance Guide',
'Vue 3 - Basic Guide',
'Vue 4 - The Mystery'
]
}
}
},
computed: {
publishedBooksMessage() {
return this.author.books.length > 0 ? 'Yes' : 'No'
}
}
}).mount('#computed-basics')
</script>
|