我想在我的页面上添加一个bootstrap模式,我在文档的头部包含了jQuery
脚本。这是模态
<!-- Modal -->
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Delete {{$title}}?
</div>
<div class="modal-body">
Are you sure you want to delete {{$body}}?
</div>
<div class="modal-footer">
<a class="btn btn-danger btn-ok">Yes</a>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
<script>
$('#confirm-delete').on('show.bs.modal', function(e) {
$(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
});
</script>
我在页面加载时遇到错误说:
[Vue warn]: Error compiling template:
...
...
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
(found in <Root>)
我不知道出了什么问题,因为我在其他项目中也使用了相同的模态,并且它可以正常工作。
答案 0 :(得分:1)
只需删除模板中的所有<script>
标记,将它们放在模板之外。
在这种情况下,您使用body作为模板,并且您将脚本放在模板(正文)中,并确保在根元素上有一个结束标记。