Vue mostrar html no grabado
¿Cómo puedo conseguir que html se interprete dentro de un enlace de bigote? En el momento en que el break (<br />
) se muestra/escapó.
Pequeña aplicación vue
var logapp = new Vue({
el: '#logapp',
data: {
title: 'Logs',
logs: [
{ status: true, type: 'Import', desc: 'Learn<br />JavaScript', date: '11.11.2015', id: 1 },
{ status: true, type: 'Import', desc: 'Learn<br />JavaScript', date: '11.11.2015', id: 1 }
]
}
})
Y aquí está la plantilla
<div id="logapp">
<table>
<tbody>
<tr v-repeat="logs">
<td>{{fail}}</td>
<td>{{type}}</td>
<td>{{description}}</td>
<td>{{stamp}}</td>
<td>{{id}}</td>
</tr>
</tbody>
</table>
</div>
4 answers
Comenzando con Vue2, las llaves triples fueron obsoletas, debe usar v-html
.
<div v-html="task.html_content"> </div>
No está claro en el enlace de documentación en cuanto a lo que se supone que debemos colocar dentro de v-html
, sus variables van dentro de v-html
.
También, v-html
solo funciona con <div>
o <span>
pero no con <template>
.
Si quieres ver esto en vivo en una aplicación, haz clic en aquí.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-26 03:50:58
Puede usar la directiva v-html para mostrarlo. así:
<td v-html="desc"></td>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-26 15:02:47
Si usa
{{<br />}}
Se escapará. Si quieres html raw, tienes que usar
{{{<br />}}}
EDIT (Feb 5 2017): Como @ hitautodestruct señala, en vue 2 deberías usar v-html en lugar de tirantes rizados triples.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-19 21:04:37
Vue de forma predeterminada se envía con la directiva v-html para mostrarlo, se enlaza al elemento en sí en lugar de usar el enlace de bigote normal para variables de cadena.
Así que para tu ejemplo específico necesitarías:
<div id="logapp">
<table>
<tbody>
<tr v-repeat="logs">
<td v-html="fail"></td>
<td v-html="type"></td>
<td v-html="description"></td>
<td v-html="stamp"></td>
<td v-html="id"></td>
</tr>
</tbody>
</table>
</div>