My requirement is something like this.
I am rendering a question paper from an object using v-for.
Once the user select an answer for a question, the question number (index) has to be v-model with that answer. How can I achieve this? this is my code.
<template lang="html">
<div class="container">
<div class="" v-for="(question,index) in questions">
<h1>Question {{index}}</h1>
<p>{{question.question}}</p>
<input type="radio" name="index" value="1">{{question.answer1}}<br>
<input type="radio" name="index" value="2">{{question.answer2}}<br>
<input type="radio" name="index" value="3">{{question.answer3}}
</div>
<hr>
<button type="button" name="button" class="btn">Save and Submit</button>
</div>
</template>
<script>
export default {
data(){
return{
questions:[
{question:"what is the capital of france?",answer1:"paris",answer2:"normandy",answer3:"rome"},
{question:"what is the capital of france?",answer1:"paris",answer2:"normandy",answer3:"rome"},
{question:"what is the capital of france?",answer1:"paris",answer2:"normandy",answer3:"rome"}]
}
}
}
</script>
Use a v-model to in the radioboxes.
A simple way to do that is to create a selectedAnswer property in each question and bind v-model to it, like:
<input type="radio" value="1" v-model="question.selectedAnswer">{{question.answer1}}<br>
Notice also that I removed the name. You were using the same name attributes to all checkboxes, and HTML will only allow one selected radio per group (per name)
To get an array of selected answers, you could simply create a computed property that maps the selected answers into an array. In the example below, the this.answers computed property is available with the answers.
Full demo below.
new Vue({
el: '#app',
data() {
return {
questions: [{
question: "what is the capital of france?",
answer1: "paris",
answer2: "normandy",
answer3: "rome",
selectedAnswer: null
},
{
question: "what is the capital of france?",
answer1: "paris",
answer2: "normandy",
answer3: "rome",
selectedAnswer: null
},
{
question: "what is the capital of france?",
answer1: "paris",
answer2: "normandy",
answer3: "rome",
selectedAnswer: null
}
]
}
},
computed: {
answers() {
return this.questions.map(q => q.selectedAnswer);
}
}
});
<script src="https://unpkg.com/vue"></script>
<div id="app">
Answers: {{ answers }}
<div class="container">
<div class="" v-for="(question,index) in questions">
<h1>Question {{index}}</h1>
<p>{{question.question}} | selected: {{question.selectedAnswer || 'none'}}</p>
<input type="radio" value="1" v-model="question.selectedAnswer">{{question.answer1}}<br>
<input type="radio" value="2" v-model="question.selectedAnswer">{{question.answer2}}<br>
<input type="radio" value="3" v-model="question.selectedAnswer">{{question.answer3}}
</div>
<hr>
<button type="button" name="button" class="btn">Save and Submit</button>
</div>
</div>
I feel v-model might not be the right solution in this case. Here is what I suggest you to do.
<template lang="html">
<div class="container">
<div class="" v-for="(question,index) in questions">
<h1>Question {{index}}</h1>
<p>{{question.question}}</p>
<input type="radio" :name="index" :value="question.answer1" #click="answerSelect(index, question.answer1)">{{question.answer1}}<br>
<input type="radio" :name="index" :value="question.answer2" #click="answerSelect(index, question.answer2)">{{question.answer2}}<br>
<input type="radio" :name="index" :value="question.answer3" #click="answerSelect(index, question.answer3)">{{question.answer3}}
</div>
<hr>
<button type="button" name="button" class="btn">Save and Submit</button>
</div>
</template>
<script>
export default {
data() {
return {
questions: [
{
question: "what is the capital of france?",
answer1: "paris",
answer2: "normandy",
answer3: "rome"
},
{
question: "what is the capital of france?",
answer1: "paris",
answer2: "normandy",
answer3: "rome"
},
{
question: "what is the capital of france?",
answer1: "paris",
answer2: "normandy",
answer3: "rome"
}
]
};
},
methods: {
answerSelect(questionIndex, answer) {
const questions = [
...this.questions.slice(0, questionIndex),
{ ...this.questions[questionIndex], solution: answer },
...this.questions.slice(questionIndex + 1, this.questions.length)
];
this.questions = questions;
}
}
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
Here is a link to the code sandbox.
https://codesandbox.io/s/o5r2xqypo9
<template lang="html">
<div class="container">
<div class="" v-for="(question,index) in questions">
<h1>Question {{index}}</h1>
<p>{{question.question}}</p>
<input type="radio" :name="index" :value="question.answer1" #click="pushAnswers(index, 1)">{{question.answer1}}<br>
<input type="radio" :name="index" :value="question.answer2" #click="pushAnswers(index, 2)">{{question.answer2}}<br>
<input type="radio" :name="index" :value="question.answer3" #click="pushAnswers(index, 3)">{{question.answer3}}
</div>
<hr>
<button type="button" name="button" class="btn">Save and Submit</button>
</div>
</template>
Method
pushAnswers(questionIndex,answer) {
this.answerSet[questionIndex] = answer;
console.log(this.answerSet);
}
Related
I need following to work. I have an input field (in my Code number1) and I need to autofill (not autocomplete) the other input fields (in my Code autofill1 + autofill2).
I'm working with Bootstrap Vue (Bootstrap 4.6 and Vue.js 2).
Here is my code:
<template>
<div class="m-2 mt-3">
<table class="table table-striped mt-2">
<tbody>
<h5 class="ml-1">Informations</h5>
<tr>
<div class="row">
<div class="col-md-6 m-1">
<div class="mt-2">number1</div>
<b-form-input class="form-control" placeholder="1234567" id="number1" />
</div>
</div>
<div class="row">
<div class="col-md-5 ml-1 mr-1">
<div class="mt-2">autofill1</div>
<b-form-select id="autofill1"> </b-form-select>
</div>
<div class="col-md-5 ml-1 mr-1">
<div class="mt-2">autofill2</div>
<b-form-select id="autofill2"> </b-form-select>
</div>
<div class="row">
<div class="col-md-3 mt-2 ml-1">
<b-button variant="success" type="submit"><b-icon icon="check-circle-fill"></b-icon> Save Changes</b-button>
</div>
</div>
</div>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
};
</script>
<style scoped>
</style>
So my goal is to load some data (first guess was an json file) into my script and after I write a matching number (also possible that its a text) in input field number1 the other two fields will be autofilled.
Thanks in advance for helping me out!
Structure json data:
[
{ "number": 1234567, "autofill1": "Hello", "autofill2": "Goodbye" },
{ "number": 9876543, "autofill1": "Ciao", "autofill2": "Arrivederci" },
{ "number": 1346795, "autofill1": "Hallo", "autofill2": "Tschuess" }
]
Something like this would work: Example
<template>
<div>
<input type="number" placeholder="1234567" v-model.number="number1" />
<input type="text" :value="getAutofill.autofill1" />
<input type="text" :value="getAutofill.autofill2" />
</div>
</template>
<script>
export default {
computed: {
getAutofill(){
if (!this.data.find(item => item.number == this.number1)) return ["",""]
return this.data.find(item => item.number == this.number1)
}
},
data() {
return {
number1: undefined,
data: [
{ "number": 1234567, "autofill1": "Hello", "autofill2": "Goodbye" },
{ "number": 9876543, "autofill1": "Ciao", "autofill2": "Arrivederci" },
{ "number": 1346795, "autofill1": "Hallo", "autofill2": "Tschuess" }
]
}
}
};
</script>
you need to add some things to the data and than watch for the variable number1 to change...
<template>
<div class="m-2 mt-3">
<table class="table table-striped mt-2">
<tbody>
<h5 class="ml-1">Informations</h5>
<tr>
<div class="row">
<div class="col-md-6 m-1">
<div class="mt-2">number1</div>
<b-form-input class="form-control" placeholder="1234567" id="number1" v-model="number1" />
</div>
</div>
<div class="row">
<div class="col-md-5 ml-1 mr-1">
<div class="mt-2">autofill1</div>
<b-form-input class="form-control" id="autofill1" v-model="autofill1" />
</div>
<div class="col-md-5 ml-1 mr-1">
<div class="mt-2">autofill2</div>
<b-form-input class="form-control" id="autofill2" v-model="autofill2" />
</div>
<div class="row">
<div class="col-md-3 mt-2 ml-1">
<b-button variant="success" type="submit"><b-icon icon="check-circle-fill"></b-icon> Save Changes</b-button>
</div>
</div>
</div>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
data(){
return {
number1: "",
autofill1: "",
autofill2: "",
jsonDATA: {...}
}
},
methods: {
findData(key) {
for(let i=0; i < this.jsonDATA.length; i++){
if(this.jsonDATA[i]['number'] === key) return element[i]
}
// add somthing when no data in array...
}
},
watch: {
number1(){
try {
let tmp = this.findData(this.number1)
this.autofill1 = tmp['autofill1']
this.autofill2 = tmp['autofill2']
}
}
}
};
</script>
<style scoped>
</style>
I havent tested this but this should work... This is not complete, you need to add some behaviour what to do when no data is found...
I got these two radio buttons in my page:
<input type="radio" :id="DIGITAL_INVOICE_DIGITAL" name="digitalInvoice" :value="false" v-model="digitalInvoice"/>
<input type="radio" :id="DIGITAL_INVOICE_PAPER" name="digitalInvoice" :value="false" v-model="digitalInvoice"/>
They are not part of <base-radio-list> and I don't want them to be.
As part of making user choice effective, both of them are not selected in the first time, thus, there need to be a validation to check if the user chose or not.
I want to make this validation using vee-validate, how can I make it ?
Below you can find validation using ValidationProvider from vee-validate.
You can work on top of this codesandbox.
Let me know how it goes.
Test.Vue
<template>
<div class="columns is-multiline">
<div class="column is-6">
<p class="control">
<ValidationProvider
ref="provider"
rules="oneOf:1,2"
v-slot="{ errors }"
>
<label class="radio">
<input
name="digitalInvoice"
value="1"
type="radio"
v-model="digitalInvoice"
/>
Yes
</label>
<label class="radio">
<input
name="digitalInvoice"
value="2"
type="radio"
v-model="digitalInvoice"
/>
No
</label>
<br />
<p class="control">
<b>{{ errors[0] }}</b>
</p>
</ValidationProvider>
<br />
</p>
</div>
</div>
</template>
<script>
import { ValidationProvider, extend } from "vee-validate";
import { oneOf } from "vee-validate/dist/rules";
extend("oneOf", {
...oneOf,
message: "Choose one",
});
export default {
name: "radio-buttons-test",
components: {
ValidationProvider,
},
data() {
return {
digitalInvoice: false,
};
},
mounted() {
this.$refs.provider.validate();
},
};
</script>
App.vue
<template>
<div id="app">
<Test />
</div>
</template>
<script>
import Test from "./components/Test";
export default {
name: "App",
components: {
Test,
},
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
In Vue, the value of the input and the value of the data object are the same.
For the input radios that are more than one element with the same v-model, the name attribute is ignored and the value stored in the data will be equal to the value attribute of the currently selected radio input.
<input type="radio" :id="DIGITAL_INVOICE_DIGITAL" :value="value1" v-model="digitalInvoice"/>
<input type="radio" :id="DIGITAL_INVOICE_DIGITAL" :value="value2" v-model="digitalInvoice"/>
and your vue data is:
data: {
digitalInvoice: "value1"
}
for unchecked try:
data: {
digitalInvoice: ""
}
I am working on Vue.JS and I tried to use local-storage with it to save data. In my code, I can store and retrieve all data with local-storage except line-through effect. Here, I am trying to store actual boolean value of line-through effect in local-storage and want to retrieve that value on to-do list app.
<title>To Do List</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>
<style>
.taskDone {
text-decoration: line-through;
}
</style>
</head>
<body>
<div id="todo-list" class="container">
<div class="container col-sm-8 col-sm-offset-2">
<h1 class="text-center"> <big><b> To Do List </b> </big></h1>
<h5 class="text-center"> <span v-show="itemsTodo.length"> ({{ itemsTodo.length }} pending) </span></h5>
<div class="col-md-8">
<button v-if="state === 'default'" class="btn btn-primary" #click="changeState('edit') ">Add Item</button>
<button v-else class="btn btn-info" #click="changeState('default')">Cancel</button>
</div>
<br>
<br>
<div v-if="state === 'edit'" >
<div class="col-sm-4">
<input class='form-control' v-model="newItem" type="text" placeholder="Type here" #keyup.enter="saveItem" >
</div>
<div class="col-sm-4">
<input class="form-control" v-model="newdate" type="date" type="text"/>
</div>
<div class="col-sm-4">
<button class='btn btn-primary btn-block' v-bind:disabled="newItem.length === 0"#click= "saveItem">Save Item</button>
</div>
</div>
<br>
<br>
<ul type="none" class="list-group">
<li class="list-group-item" v-for="(item,index,date) in items" :class="{taskDone : item.completed}" >
<h4>
<input type="checkbox" v-model="item.completed" #click="item.completed = !item.completed">
<button class="btn btn-primary " #click.stop="removeitems(index)">× </button>
<b><i> {{ item.label }} {{ item.date }} </i></b></h4>
</li>
</ul>
<h2 v-if="items.length === 0">Nice Job! Nothing in TO DO LIST</h2>
<div class="col-sm-4">
<button class="btn btn-warning btn-block" #click="clearcompleted"> Clear Completed</button>
</div>
<div class="col-sm-4">
<button class="btn btn-danger btn-block" #click="clearAll"> Clear All</button>
</div>
</div>
</div>
2. Vue.JS code
<script src="https://unpkg.com/vue" ></script>
<script>
var todolist = new Vue({
el: '#todo-list',
data : {
state : 'edit',
header: 'To Do List',
newItem: '',
newdate: '',
items: [
{
label:'coffee',
completed:false,
date:'2019-06-20' ,
},
{
label:'tea',
completed:false,
date:'2019-06-19' ,
},
{
label:'milk',
completed:false,
date:'2019-06-19' ,
},
]
},
computed:{
itemsDone(){
return this.items.filter(items => items.completed)
},
itemsTodo(){
return this.items.filter(items =>! items.completed)
},
},
methods:{
saveItem: function(){
if (this.newItem != ''){
this.items.push({
label:this.newItem,
completed: false,
date : this.newdate,
});
this.newItem = '';
this.newdate = '';
}},
changeState: function(newState){
this.state = newState;
this.newItem = '';
this.newdate = '';
},
removeitems(index){
this.items.splice(index,1);
},
clearcompleted (){
this.items = this.itemsTodo;
},
clearAll: function(){
this.items = [ ];
},
},
mounted(){
console.log('App Mounted!');
if (localStorage.getItem('items')) this.items = JSON.parse(localStorage.getItem('items'));
},
watch: {
items:{
handler(){
localStorage.setItem('items',JSON.stringify(this.items));
},
},
},
});
</script>
I expect correct boolean value of line-through effect to be stored in local-storage. So that, appropriate effect will show on browser.
You are just watching items. If you change something in a item (in your case completed) the handler will not be called and your change is not stored.
You could use a "deep" watcher but i suggest to call your save logic whenever you changed something.
I am new to Vue but I think that this can be really useful.
I have my first problem this simplified example
var appvue = new Vue({
el: '#appvue',
data: {
selectedProd: []
}
});
body {
background: #20262E;
}
.form-row{
width:24%;
display:inline-block;
}
#appvue {
background: #fff;
padding:10px;
}
#prod_adjust{
margin-top:20px;
background: #eee
}
<script src="https://cdn.jsdelivr.net/npm/vue#2.5.17/dist/vue.js"></script>
<div class="prod-wrap" id="appvue">
<div class="form-row">
<input v-model="selectedProd" name="product-1260" id="product-1260" type="checkbox" value="1260">
<label for="product-1260">
<div class="thumb">
<img src="https://picsum.photos/100/100">
</div>
<div class="details">
<span class="brand">Brand 1</span>
<span class="product-title">Product 1</span>
</div>
</label>
</div>
<div class="form-row">
<input v-model="selectedProd" name="product-1261" id="product-1261" type="checkbox" value="1261">
<label for="product-1261">
<div class="thumb">
<img src="https://picsum.photos/100/100">
</div>
<div class="details">
<span class="brand">Brand 2</span>
<span class="product-title">Product 2</span>
</div>
</label>
</div>
<div class="form-row">
<input v-model="selectedProd" name="product-1263" id="product-1263" type="checkbox" value="1263">
<label for="product-1263">
<div class="thumb">
<img src="https://picsum.photos/100/100">
</div>
<div class="details">
<span class="brand">Brand 3</span>
<span class="product-title">Product 3</span>
</div>
</label>
</div>
<div class="form-row">
<input v-model="selectedProd" name="product-1264" id="product-1264" type="checkbox" value="1264">
<label for="product-1264">
<div class="thumb">
<img src="https://picsum.photos/100/100">
</div>
<div class="details">
<span class="brand">Brand 4</span>
<span class="product-title">Product 4</span>
</div>
</label>
</div>
<div id="prod_adjust">
<p v-for="product in selectedProd">{{product}}</p>
</div>
</div>
I have a lot of products like the checkboxes above. I need to have the list of checked items in another place.
I did this with v-model and v-for - but my main problem is now that there are sending only the value from the checkboxes - I also need img-src, brand, product-title - all these parameters I also can have more attributes in an input.
But how I can pass them in data: { selectedProd:[]} with Vue?
Or I do I need to create a separate JS function which will collect all this data and send it to the array selectedProd?
Thank you in advance
You would want to create an object with the data you need for the product. Then you can use v-for to loop through and display them the way you'd like.
In the example, I included a computed function that automatically returns the ones that get checked. This is done by v-model binding the checkbox to a flag inside your object. In this example, I called it selected, for simplicity.
var appvue = new Vue({
el: '#appvue',
data: {
products: [{
id: 1260,
brand: "Brand A",
product: "Bubblegun",
image: "https://picsum.photos/100/100",
selected: false
}, {
id: 1261,
brand: "Brand B",
product: "Bubblegum",
image: "https://picsum.photos/100/100",
selected: false
}],
},
computed: {
selectedProd() {
return this.products.map(product => {
if (product.selected) return product
})
}
}
})
body {
background: #20262E;
}
.form-row {
width: 24%;
display: inline-block;
}
#appvue {
background: #fff;
padding: 10px;
}
#prod_adjust {
margin-top: 20px;
background: #eee
}
<script src="https://cdn.jsdelivr.net/npm/vue#2.5.17/dist/vue.min.js"></script>
<div class="prod-wrap" id="appvue">
<div class="form-row" v-for="product in products">
<input v-model="product.selected" name="product-1260" id="product-1260" type="checkbox">
<label for="product-1260">
<div class="thumb">
<img :src="product.image">
</div>
<div class="details">
<span class="brand">{{product.brand}}</span>
<span class="product-title">{{product.product}}</span>
</div>
</label>
</div>
<div id="prod_adjust">
<p v-for="product in selectedProd">{{product}}</p>
</div>
</div>
If you have the input as a JSON which has all the properties you are asking for (product_ID, img src, brand name) then you can assign the object to v-model instead of product_ID.
Your JSON array should look like this,
productsArray: [
{ productID: 1260,
product-title: "Product 1",
brand: "Brand 1",
img: "https://picsum.photos/100/100"
},
{ productID: 1261,
product-title: "Product 2",
brand: "Brand 2",
img: "https://picsum.photos/100/100"
},]
Then inside v-for you can read each object and when selected you can assign the entire object into selectedProd
I used next way finally
vueproducts = function(){
appvue.selectedProd = [];
var tempprod = {};
$('.form-row input').each(function(){
if ($(this).is(":checked")){
tempprod.id = $(this).val();
tempprod.img = $(this).parent().find('img').attr('src');
tempprod.title = $(this).parent().find('.product-title').html();
appvue.selectedProd.push(tempprod);
tempprod = {};
};
});
}
Trying to become friends with VUEJS. Got stuck on some simple stuff, couldn't google it. So I'm using MuseUi framework in my App. Well I want to do a simple thing, change the value of the property for each specific element on hover
<mu-paper :zDepth="1" v-on:mouseover=" ???? " class="searchBox">
I need to change:zDepth to 3 for example, on hover of the element. How could I achieve that?
full code snippet
<template>
<div>
<div class="column is-one-quarter">
<mu-paper :zDepth="paperHover" v-on:mouseover="changePaper" class="searchBox">
<mu-text-field fullWidth="true" :hintText="searchHint" v-model="query" class="demo-radio"/><br/>
<mu-radio label="Name" name="group" nativeValue="1" v-model="selected" class="demo-radio"/>
<mu-radio label="Manager" name="group" nativeValue="2" v-model="selected" class="demo-radio"/>
<mu-radio label="Department" name="group" nativeValue="3" v-model="selected" class="demo-radio"/>
<mu-radio label="Stage" name="group" nativeValue="4" v-model="selected" class="demo-radio"/>
<mu-radio label="Deadline" name="group" nativeValue="5" v-model="selected" class="demo-radio"/>
<mu-radio label="Start Date" name="group" nativeValue="6" v-model="selected" class="demo-radio"/>
</mu-paper>
</div>
<div class="column is-one-column">
<mu-float-button icon="add" v-on:click="openModal"/>
</div>
<div class="column">
<draggable v-model="projects" #start="drag=true" #end="drag=false">
<transition-group name="list-complete staggered-fade" tad="ul" :css="false" :before-enter="beforeEnter" :enter="enter" :leave="leave">
<li v-for="(project, index) in projectsComputed" :key="project.name" :data-index="index" class="column is-one-third list-complete-item">
<mu-paper :zDepth="3">
<mu-icon-button icon="delete" class="delete-button"></mu-icon-button>
<article class="media">
<div class="media-content">
<div class="content">
<div class="project-name has-text-centered">
<span>{{project.name}}</span>
</div>
<mu-badge :content="project.stage.name" primary slot="right"/>
<!--<div class="project-status has-text-centered">-->
<!--<span>{{project.stage.name}}</span>-->
<!--</div>-->
<div class="project-desc-list has-text left">
<span>Manager: </span> <span>{{project.manager.name}}</span>
</div>
<div class="project-desc-list has-text left">
<span>Department: </span> <span>{{project.department.name}}</span>
</div>
<div class="project-desc-list has-text left">
<span>Start Date: </span> <span>{{project.started_from}}</span>
</div>
<div class="project-desc-list has-text left">
<span>Dealine: </span> <span>{{project.deadline}}</span>
</div>
<p class="project-description">
{{project.description}}
</p>
</div>
</div>
</article>
</mu-paper>
</li>
</transition-group>
</draggable>
</div>
<div id="modal-ter" :class="[isActive ? activeClass : '', modal]">
<div class="modal-background" v-on:click="openModal"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Add New Project</p>
<button v-on:click="openModal" class="delete"></button>
</header>
<section class="modal-card-body">
<div class="column is-one-third">
<div class="field">
<label class="label">Project Name</label>
<p class="control">
<input class="input" v-model="newProject.name" type="text" placeholder="Text input">
</p>
</div>
</div>
<div class="column is-one-third">
<div class="field">
<label class="label">Project Description</label>
<p class="control">
<input class="input" v-model="newProject.description" type="text" placeholder="Text input">
</p>
</div>
</div>
<div class="column is-one-third">
<div class="field">
<label class="label">Start Date</label>
<p class="control">
<input class="input" v-model="newProject.started_from" type="text" placeholder="Text input">
</p>
</div>
</div>
<div class="column is-one-third">
<div class="field">
<label class="label">Deadline</label>
<p class="control">
<input class="input" v-model="newProject.deadline" type="text" placeholder="Text input">
</p>
</div>
</div>
<div class="column is-one-third">
<div class="field">
<label class="label">Manager</label>
<p class="control">
<input class="input" v-model="newProject.manager.name" type="text" placeholder="Text input">
</p>
</div>
</div>
<div class="column is-one-third">
<div class="field">
<label class="label">Department</label>
<p class="control">
<input class="input" v-model="newProject.department.name" type="text" placeholder="Text input">
</p>
</div>
</div>
<div class="column is-one-third">
<div class="field">
<label class="label">Stage</label>
<p class="control">
<input class="input" type="text" v-model="newProject.stage.name" placeholder="Text input">
</p>
</div>
</div>
</section>
<footer class="modal-card-foot">
<a v-on:click="createProject" class="button is-success">Save changes</a>
<a class="button">Cancel</a>
</footer>
</div>
</div>
</div>
</template>
<style scoped>
.demo-radio {
min-width: 8em;
}
.searchBox {
padding: 2em;
}
.project-status {
position: absolute;
top: 0.3em;
left: 0.3em;
background-color: #ffdb57;
padding: 0.2em;
padding-left: 0.5em;
padding-right: 0.5em;
border-radius: 0.3em;
}
.project-name {
font-weight: 900;
}
.project-description {
margin-top: 0.5em;
padding-top: 1em;
border-top: 1px solid lightgrey;
}
.project-desc-list span:first-of-type{
font-weight: 900;
}
.box {
position: relative;
}
.project-name {
text-align: center;
}
.delete-button {
background-color: rgba(255, 8, 8, 0.4);
transition: all .25s ease-in;
float: right;
position: absolute;
right: 0.3em;
top: 0.3em;
}
.delete-button:hover, .delete-button:focus{
background-color: rgba(255, 0, 0, 0.68);
}
.column{
display: inline-block;
padding: 1em;
}
.list-complete-item {
transition: all 1s;
}
.list-complete-enter, .list-complete-leave-active {
opacity: 0;
}
</style>
<script >
export default {
data(){
return {
loading: false,
isActive: false,
paperHover: 3,
modal: 'modal',
searchHint: 'Search by ...',
activeClass: 'is-active',
query: "",
selected: "",
projects: [],
newProject: {
name: '',
description: '',
started_from: '',
deadline: '',
manager: {
name: ''
},
department: {
name: ''
},
stage: {
name: ''
}
},
}
},
options: {
segmentShowStroke: false
},
mounted() {
this.getData();
},
computed: {
projectsComputed: function () {
var vm = this;
if(this.selected == '1' || this.selected == ""){
this.searchHint = "Search by Name";
return this.projects.filter(function (project) {
return project.name.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1;
})
}else if(this.selected == '2'){
this.searchHint = "Search by Manager";
return this.projects.filter(function (project) {
return project.manager.name.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1;
})
}else if(this.selected == '3'){
this.searchHint = "Search by Department";
return this.projects.filter(function (project) {
return project.department.name.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1;
})
}else if(this.selected == '4'){
this.searchHint = "Search by Stage";
return this.projects.filter(function (project) {
return project.stage.name.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1;
})
}else if(this.selected == '5'){
this.searchHint = "Search by Deadline";
return this.projects.filter(function (project) {
return project.deadline.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1;
})
}else if(this.selected == '6'){
this.searchHint = "Search by Start Date";
return this.projects.filter(function (project) {
return project.started_from.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1;
})
}
}
},
methods: {
changePaper: function () {
this.paperHover = 6 ;
},
beforeEnter: function (el) {
el.style.opacity = 0
el.style.height = 0
},
enter: function (el, done) {
var delay = el.dataset.index * 150
setTimeout(function () {
Velocity(
el,
{ opacity: 1, height: '1.6em' },
{ complete: done }
)
}, delay)
},
leave: function (el, done) {
var delay = el.dataset.index * 150
setTimeout(function () {
Velocity(
el,
{ opacity: 0, height: 0 },
{ complete: done }
)
}, delay)
},
getData() {
this.loading = true;
axios.get('/project/').then(({data}) => this.projects = data).then(() => this.loading = false)
},
openModal: function(){
if(this.isActive){
this.isActive = false;
}else {
this.isActive = true;
}
},
createProject() {
axios.post('project/store', this.newProject)
}
}
}
</script>
enter code here
The easiest way is probably to wrap the mu-paper component in another component where you can encapsulate the hover behavior.
// MuPaperHover.vue
<template>
<mu-paper :z-depth="zDepth" #mouseenter.native="zDepth = 3" #mouseleave.native="zDepth = 1">
<slot/>
</mu-paper>
</template>
<script>
export default {
data() {
return {
zDepth: 1,
};
},
};
</script>
You can then use mu-paper-hover in place of mu-paper.
I'm not familiar with MuseUI. However, I've written a Vue.js training course. In Vue, the area where your "????" are, should be a JavaScript expression. A typical practice is to call a method on your Vue instance that would then update the value of the property for the specific element. Without more details, it's hard to provide specifics.
The bottom line is, the "????" can be a JavaScript expression.