简体   繁体   English

在 Vue.js 中初始化物化元素

[英]Initializing materialize elements in Vue.js

How can I initialize the Materializes' select or modal elements in Vue.js?如何在 Vue.js 中初始化 Materialise 的选择或模态元素? When I add the following code in my document ready the elements do not work.当我在准备好的文档中添加以下代码时,元素不起作用。

 <script> $(document).ready(function() { $('.modal-trigger').leanModal('open'); $('select').material_select(); }); //Vue.js code here... </script>

You could try and call this code in one of Vue's lifecycle hooks (see this diagram to find out where exactly they're executed), you'll probably want to use mounted .您可以尝试在 Vue 的生命周期钩子之一中调用此代码(请参阅 此图以了解它们的确切执行位置),您可能希望使用mounted

But keep in mind this isn't really a bulletproof solution.但请记住,这并不是真正的防弹解决方案。 Vue may manipulate the DOM in different ways later and as such isn't necessarily compatible with Materialize. Vue 以后可能会以不同的方式操作 DOM,因此不一定与 Materialize 兼容。 The best solution in these cases is always to find a framework-specific implementation of the components you're trying to use, eg Vue Material .在这些情况下,最好的解决方案始终是找到您尝试使用的组件的特定于框架的实现,例如Vue Material

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM