运行 ❯
获取你
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <title>template with v-if</title> <style> #app { border: dashed black 1px; width: 130px; padding: 0 20px 20px 20px; font-weight: bold; background-color: lightgreen; } img { width: 100%; } </style> </head> <body> <h1>Example with template and 'v-if'</h1> <p>Using the template tag, we can render more than one element with 'v-if'.</p> <div id="app"> <template v-if="text.includes('pizza')"> <p>The text includes the word 'pizza'</p> <img src="img_pizza.svg"> </template> <p v-else>The word 'pizza' is not found in the text</p> </div> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> <script> const app = Vue.createApp({ data() { return { text: 'I like burrito, pizza, Thai beef salad, pho soup and tagine.' } } }) app.mount('#app') </script> </body> </html>