admin管理员组文章数量:1300174
I am new with Vue.js and I want to make my project with Materialize. I try a lot of plugins like: vue-materialize (), vue-material-ponents() and didn't work. I also tried to add jQuery plugin to webpack and I don't have any solution:
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery'
}),
Now I am trying to make work a input select field. How can I make this work?
I am new with Vue.js and I want to make my project with Materialize. I try a lot of plugins like: vue-materialize (https://github./paulpflug/vue-materialize), vue-material-ponents(https://www.npmjs./package/vue-material-ponents) and didn't work. I also tried to add jQuery plugin to webpack and I don't have any solution:
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery'
}),
Now I am trying to make work a input select field. How can I make this work?
Share Improve this question edited Jan 3, 2017 at 14:41 Allan Pereira 2,5704 gold badges22 silver badges28 bronze badges asked Dec 26, 2016 at 11:17 FranciscoFrancisco 1632 gold badges5 silver badges18 bronze badges 1- Have a look at this question on material input and this fiddle. – Saurabh Commented Dec 26, 2016 at 11:21
3 Answers
Reset to default 6You can use Vue-Material to materialize your Vue project. Following are the steps that you need to follow:
- Install vuematerial
$ npm install --save vue-material
- Import vuematerial to your main.js
import VueMaterial from 'vue-material'
import 'vue-material/dist/vue-material.css'
- Start using vuematerial in your project
Vue.use(VueMaterial)
A sample main.js
file should look something like this:
import Vue from 'vue';
import VueMaterial from 'vue-material'
import 'vue-material/dist/vue-material.css';
import App from './App';
import router from './router';
Vue.use(VueMaterial)
Vue.config.productionTip = false;
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
ponents: { App },
});
You will now be able to use vuematerial ponents inside your template.
Here is my setup to use Materialize with Vue Webpack template:
build/webpack.base.conf.js
var webpack = require('webpack')
module.exports =
resolve: {
alias: {
...
'jquery': 'materialize-css/node_modules/jquery/dist/jquery.js'
}
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
...
options: {
limit: 10000
....
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery',
'window.$': 'jquery',
'window.jQuery': 'jquery'
})
]
}
index.html
<head>
...
<link href="https://fonts.googleapis./icon?family=Material+Icons" rel="stylesheet">
</head>
package.json
{
...
"dependencies": {
"materialize-css": "^0.98.2",
...
"devDependencies": {
"@types/jquery": "^2.0.43", // ==> if using typescript
src/main.js
import 'materialize-css'
import 'materialize-css/dist/css/materialize.css'
So, for a "input select field" like below:
<div class="input-field" ref="myInput">
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Select</label>
</div>
...you could put this code in your mounted
lifecycle hook:
mounted() {
$(this.$refs.myInput).material_select()
Vue.js
given link by you reffers Materializecss
and both are look same. Here I have added fully working code with drop down button
.
You can just copy and paste following code to a text file and save it as a .html file (ex: name.html
). You can edit this code by adding relevant code in between the ment <!--your code start-->
and <!--your code end-->
.
Click the Run code Snippet
button below to test online and you can see DROP ME!
button. Once you click it you can see how drop down works.
More details refer materializecss which is more user friendly than the link you have given.
<!DOCTYPE html>
<html>
<head>
<title>Slider</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/materialize/0.97.3/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<!--your code start-->
<!-- Dropdown Trigger -->
<a class='dropdown-button btn' href='#' data-activates='dropdown1'>Drop Me!</a>
<!-- Dropdown Structure -->
<ul id='dropdown1' class='dropdown-content'>
<li><a href="#!">one</a></li>
<li><a href="#!">two</a></li>
<li class="divider"></li>
<li><a href="#!">three</a></li>
</ul>
<!--your code end-->
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery./jquery-2.1.1.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare./ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
</body>
</html>
本文标签: javascriptMaterialize inside VuejsStack Overflow
版权声明:本文标题:javascript - Materialize inside Vue.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741658745a2390911.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论