【发布时间】:2019-01-20 03:51:21
【问题描述】:
我想在 nuxt.js 中使用这些神奇的东西,服务器端渲染很重要。 但是官方网站上的教程不是很清楚,我得到了一些错误。 我运行命令“npm i materialize-css”来安装它。 下面的版本: "materialize-css": "^0.100.2"
我使用正常的方式来初始化“下拉”组件,当我在按钮上移动鼠标或单击按钮时,什么也没发生。 “下拉菜单”不起作用。
html代码:
<ul class="right hide-on-med-and-down">
<li>
<a class="font-color" href="#">
<i class="material-icons right">chrome_reader_mode
</i>Blog
</a>
</li>
<li>
<a class="dropdown-button font-color" data-activates="drop-list">
<i class="material-icons right">arrow_drop_down
</i>Test
</a>
</li>
</ul>
<!--dropdown list-->
<ul id='drop-list' class='dropdown-content'>
<li>
<a href="#!" class="grey-text">A</a>
</li>
<li class="divider" tabindex="-1"></li>
<li>
<a href="#!" class="grey-text">B</a>
</li>
<li class="divider" tabindex="-1"></li>
<li>
<a href="#!" class="grey-text"><i class="material-icons ">message</i>C
</a>
</li>
</ul>
组件初始化代码:
mounted() {
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.dropdown-button');
let options={
inDuration: 300,
outDuration: 225,
constrainWidth: true, // Does not change width of dropdown to that of the activator
hover: true, // Activate on hover
gutter: 0, // Spacing from edge
belowOrigin: true, // Displays dropdown below the button
alignment: 'left', // Displays dropdown with edge aligned to the left of button
stopPropagation: false // Stops event propagation
}
var instances = M.Dropdown.init(elems, options);
});
}
然后我尝试通过 jquery 初始化它,但我也得到了错误。
'$ 未定义'。或“$.dropdown() 不是函数”
我不知道如何将 jquery 和具体化导入到我的 nuxt.js 项目中。 这是jquery的初始化代码。
mounted(){
$('.dropdown-button').dropdown({
inDuration: 300,
outDuration: 225,
constrainWidth: true, // Does not change width of dropdown to that of the activator
hover: true, // Activate on hover
gutter: 0, // Spacing from edge
belowOrigin: true, // Displays dropdown below the button
alignment: 'left', // Displays dropdown with edge aligned to the left of button
stopPropagation: false // Stops event propagation
});
}
'nuxt.config.js':
module.exports = {
css: [
'materialize-css/dist/css/materialize.css'
],
plugins: [
$:jquery
]
......
}
现在我不知道如何在 nuxt.js 中使用它。 谁能告诉我如何使用它?对此,我真的非常感激 。谢谢
【问题讨论】:
标签: vue.js materialize nuxt.js