vue中template的三种写法示例
网络编程 2021-07-04 14:06www.168986.cn编程入门
这篇文章主要介绍了vue中template的三种写法示例,帮助大家更好的理解和学习vue,感兴趣的朋友可以了解下
第一种(字符串模板写法):
直接写在vue构造器里,这种写法比较直观,适用于html代码不多的场景,如果模板里html代码太多,不便于维护,不建议这么写.
<!DOCTYPE html> <html> <!-- WARNING! Make sure that you match all Quasar related tags to the same version! (Below it's "@1.7.4") --> <head> <!-- <link href="https://cdn.jsdelivr./npm/quasar@1.7.4/dist/quasar.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"> --> <link href="https://.mobibrw./wp-content/uploads/2020/06/quasar@1.7.4.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"> </head> <body> <div id="q-app"> </div> <!-- Add the following at the end of your body tag --> <!-- <script src="https://cdn.jsdelivr./npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="https://cdn.jsdelivr./npm/quasar@1.7.4/dist/quasar.umd.min.js"></script> --> <script src="https://.mobibrw./wp-content/uploads/2020/06/vue@2.0.0.js"></script> <script src="https://.mobibrw./wp-content/uploads/2020/06/quasar.umd@1.7.4.js"></script> <script> / Example kicking off the UI. Obviously, adapt this to your specific needs. Assumes you have a <div id="q-app"></div> in your <body> above / new Vue({ el: '#q-app', data: function () { return { version: Quasar.version } }, template: `<div class="q-ma-md"> Running Quasar v{{ version }}</div>` // ...etc }) </script> </body> </html>
第二种:
直接写在template标签里,这种写法跟写html很像。
<!DOCTYPE html> <html> <!-- WARNING! Make sure that you match all Quasar related tags to the same version! (Below it's "@1.7.4") --> <head> <!-- <link href="https://cdn.jsdelivr./npm/quasar@1.7.4/dist/quasar.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"> --> <link href="https://.mobibrw./wp-content/uploads/2020/06/quasar@1.7.4.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"> </head> <body> <div id="q-app"> <template id='template1'> <div class="q-ma-md"> Running Quasar v{{ version }} </div> </template> </div> <!-- Add the following at the end of your body tag --> <!-- <script src="https://cdn.jsdelivr./npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="https://cdn.jsdelivr./npm/quasar@1.7.4/dist/quasar.umd.min.js"></script> --> <script src="https://.mobibrw./wp-content/uploads/2020/06/vue@2.0.0.js"></script> <script src="https://.mobibrw./wp-content/uploads/2020/06/quasar.umd@1.7.4.js"></script> <script> / Example kicking off the UI. Obviously, adapt this to your specific needs. Assumes you have a <div id="q-app"></div> in your <body> above / new Vue({ el: '#q-app', data: function () { return { version: Quasar.version } }, template: '#template1' // ...etc }) </script> </body> </html>
第三种:
写在script标签里,这种写法官方推荐,vue官方推荐script中type属性加上"x-template",即:
<!DOCTYPE html> <html> <!-- WARNING! Make sure that you match all Quasar related tags to the same version! (Below it's "@1.7.4") --> <head> <!-- <link href="https://cdn.jsdelivr./npm/quasar@1.7.4/dist/quasar.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"> --> <link href="https://.mobibrw./wp-content/uploads/2020/06/quasar@1.7.4.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"> </head> <body> <div id="q-app"></div> <script type="x-template" id="template1"> <div class="q-ma-md"> Running Quasar v{{ version }} </div> </script> <!-- Add the following at the end of your body tag --> <!-- <script src="https://cdn.jsdelivr./npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="https://cdn.jsdelivr./npm/quasar@1.7.4/dist/quasar.umd.min.js"></script> --> <script src="https://.mobibrw./wp-content/uploads/2020/06/vue@2.0.0.js"></script> <script src="https://.mobibrw./wp-content/uploads/2020/06/quasar.umd@1.7.4.js"></script> <script> / Example kicking off the UI. Obviously, adapt this to your specific needs. Assumes you have a <div id="q-app"></div> in your <body> above / new Vue({ el: '#q-app', data: function () { return { version: Quasar.version } }, template: '#template1' // ...etc }) </script> </body> </html>
以上就是vue中template的三种写法示例的详细内容,更多关于vue template的资料请关注狼蚁SEO其它相关文章!
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程