Vue中template的三种写法,分别是哪种形式?

2026-04-02 09:291阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计983个文字,预计阅读时间需要4分钟。

Vue中template的三种写法,分别是哪种形式?

第一种(字符串模板写法):直接在Vue构造器中写入,这种写法比较直观,适用于HTML代码不多的场景。但如果模板中HTML代码过多,不利于维护,不推荐使用。

第一种(字符串模板写法):

直接写在vue构造器里,这种写法比较直观,适用于html代码不多的场景,但是如果模板里html代码太多,不便于维护,不建议这么写.

Vue中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="cdn.jsdelivr.net/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="www.mobibrw.com/wp-contentimg.558idc.com/uploadfile/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="cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ5F21-1.jpg"></script> --> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ56133-2.jpg"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ54058-3.jpg"></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="cdn.jsdelivr.net/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="www.mobibrw.com/wp-contentimg.558idc.com/uploadfile/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="cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ5F21-1.jpg"></script> --> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ56133-2.jpg"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ54058-3.jpg"></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="cdn.jsdelivr.net/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="www.mobibrw.com/wp-contentimg.558idc.com/uploadfile/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="cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ5F21-1.jpg"></script> --> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ56133-2.jpg"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ54058-3.jpg"></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的资料请关注易盾网络其它相关文章!

本文共计983个文字,预计阅读时间需要4分钟。

Vue中template的三种写法,分别是哪种形式?

第一种(字符串模板写法):直接在Vue构造器中写入,这种写法比较直观,适用于HTML代码不多的场景。但如果模板中HTML代码过多,不利于维护,不推荐使用。

第一种(字符串模板写法):

直接写在vue构造器里,这种写法比较直观,适用于html代码不多的场景,但是如果模板里html代码太多,不便于维护,不建议这么写.

Vue中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="cdn.jsdelivr.net/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="www.mobibrw.com/wp-contentimg.558idc.com/uploadfile/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="cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ5F21-1.jpg"></script> --> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ56133-2.jpg"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ54058-3.jpg"></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="cdn.jsdelivr.net/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="www.mobibrw.com/wp-contentimg.558idc.com/uploadfile/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="cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ5F21-1.jpg"></script> --> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ56133-2.jpg"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ54058-3.jpg"></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="cdn.jsdelivr.net/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="www.mobibrw.com/wp-contentimg.558idc.com/uploadfile/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="cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ5F21-1.jpg"></script> --> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ56133-2.jpg"></script> <script src="img.558idc.com/uploadfile/allimg/210405/1JZ54058-3.jpg"></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的资料请关注易盾网络其它相关文章!