vue 2.4.0 新增特性html
添加comments
選項來保留template
的註釋vue
官網文檔:
https://cn.vuejs.org/v2/api/#...
主要看限制 : 這個選項只在完整構建版本①中的瀏覽器內編譯②時可用。node
①:我用的是vue-cli命令生成的目錄,默認的寫法是這樣的git
`import Vue from vue`
此處的vue指的是 dist/vue.runtime.common.js
,這個能夠打開node_module/vue/package.json
main屬性查看。
因此我修改成github
import Vue from '../node_modules/vue/dist/vue.esm
②:瀏覽器內編譯
使用*.vue
文件都是經過nodejs編譯,不是瀏覽器編譯。這裏的瀏覽器內編譯指的是這樣的。vue-cli
https://stackoverflow.com/que...json
<script src="https://unpkg.com/vue@2.5.8/dist/vue.js"></script> <div id="myApp"> <div class="some-content"> This is some content </div> <!-- Comments --> <div v-html="comments"> {{ comments }} </div> <div class="some-other-content"> This is some content </div> </div> var productTemplate = new Vue({ el: '#myApp', comments: true, data: { comments: ` <!--[if mso]> <div> this div will only be shown if the condition in the comment is true, in this case the condition is: if ( mso (microsoft office) == the html rendering engine) { show the html code between the [if mso] and the [endif] } </div> <![endif]-->` } });
https://github.com/vuejs/vue/...
api
國內不多有文章介紹到,但願能給你們帶來幫助。瀏覽器
參考:this
https://cn.vuejs.org/v2/api/#comments https://stackoverflow.com/questions/47426675/vue-html-comment-handling https://github.com/vuejs/vue/issues/6177