最近我想在一个vue组件中将一个stirng转换为Dom,但它并不像我期望的那样工作.我的代码看起来像这样:
// what I wrote in the template
<div id="log">
{{libText}}
</div>
// what I wrote in js
Vue.component(... , {
template: ... ,
data: function () {
return ...
}
},
computed: {
libText:function(){
var str="<p>some html</p>";
var div = document.createElement('div');
div.innerHTML = str;
return div;
}
},
methods:{...}
})
Run Code Online (Sandbox Code Playgroud)
我得到的结果是字符串"[object HTMLDivElement]"而不是Dom.如果有人能帮助我解决这个问题,那将是非常好的
如标题所述,当孩子的 mousedown 事件被触发时,我想停止父母的点击事件。
我的 HTML 代码如下所示
<div class='parent'>
<div class='child'></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的 jquery 代码看起来像这样
$('.child').mousedown(function(){
//what can I write here to prevent parent's click event from fireing?
//I've tried event.stopPropagation() as well as
//event.stopImmediatePropagation() already
});
$('.parent').on('click',function(){...})
Run Code Online (Sandbox Code Playgroud)