Software
My POST ajax request returns 302 on a Laravel Controller
I send a POST Ajax request to a Laravel Controller but I get a 302 Found response code.
The controller is the ForgotPasswordController provided by Laravel's Auth package, so nothing special about it.
It has the guest middleware in its constructor and I found that if I remove this middleware from the constructor, the Ajax request works correctly (it returns a 200 response code).
The Ajax request has the X-CSRF-TOKEN and X-XSRF-TOKEN headers, so I don't think there is something missing.
I'm sending this Ajax request from a VueJS password reset form with the Axios library.
Why my POST request does not work if the controller has the guest middleware ?
Thanks !
Here are the headers sent with the request :
POST /password/email HTTP/1.1 Host: myapp.dev Connection: keep-alive Content-Length: 37 Pragma: no-cache Cache-Control: no-cache Origin: http://myapp.dev X-XSRF-TOKEN: eyJpdiI6IjRqTk1yTXFsXC9FVlRzckF0dUM4azdRPT0iLCJ2YWx1ZSI6IjY0MUZzaEpCTXJDcUhzUGhcL2dzYVJmalQrR3pwV3IzYWxiTSt4dVwvN2VVKzJ4b2t3XC9GcVhJcllmK3pQYVV4VGFIZG4wZ0s3NlNCTG01WEl6YzBCY2NRPT0iLCJtYWMiOiIwYmNjOTRiZGJjZTM2YjYyMWJiMzRhNTlkOTkwOWU4Y2M4NmYzYzI5NjhiMTU4MDdiMGJkMmJhYmMwODEzMDhjIn0= X-CSRF-TOKEN: nejsetydvFWgeqppZc5XQtX04b5AdXlsTKSgaydj User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36 Content-Type: application/json;charset=UTF-8 Accept: application/json, text/plain, / X-Requested-With: XMLHttpRequest Referer: http://myapp.dev/password Accept-Encoding: gzip, deflate Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4 Cookie: XSRF-TOKEN=eyJpdiI6IjRqTk1yTXFsXC9FVlRzckF0dUM4azdRPT0iLCJ2YWx1ZSI6IjY0MUZzaEpCTXJDcUhzUGhcL2dzYVJmalQrR3pwV3IzYWxiTSt4dVwvN2VVKzJ4b2t3XC9GcVhJcllmK3pQYVV4VGFIZG4wZ0s3NlNCTG01WEl6YzBCY2NRPT0iLCJtYWMiOiIwYmNjOTRiZGJjZTM2YjYyMWJiMzRhNTlkOTkwOWU4Y2M4NmYzYzI5NjhiMTU4MDdiMGJkMmJhYmMwODEzMDhjIn0%3D; laravel_session=eyJpdiI6IkJnczRHV3NcLzhLbzZWaUlvTTI2cFlBPT0iLCJ2YWx1ZSI6IkpQYytLXC9pQ1R3MTZlaEx2QWJ4bGpSd21BV25jelJKVDJkQVdcL25GSG4rQkpQc1duZHIrTjErOGt3bk5BVVVcL3FTK1c2XC83Y1NqTmxBaVZ1bkQ2TWV5Zz09IiwibWFjIjoiNzg4Y2UyNWQ0ODcxMWNkNWE3MmU4ZDY1MmIyNTE0NDgwMzFmM2ZjYzkxMzM5ZGM5ZTk5MDI4NjE4OGRkNmJjYyJ9
webpack vue compiler in 1 file in .net mvc5 environment
I have a MVC5 .Net solution wich is using Vue.js and webpack to compile. on the early days of the project someone decided to compile the .vue in separated .js files. But now with over 20 .vue files, it's a pain. My question is:
How can I transform this webpack config to compile it in a single .js file?
const fs = require("fs"); const path = require("path"); // build an object that looks like // { // "filename": "./filename.vue" // } // to list the entry points for webpack to compile. function buildEntry() { const reducer = (entry, file) => { entry[file.split(".").shift()] = `./Vue/${file}`; return entry; }; return fs.readdirSync(path.join(__dirname, "Vue")) .filter(file => file.endsWith(".vue")) .reduce(reducer, {}); } module.exports = { entry: buildEntry(), output: { path: path.join(__dirname, "Vue"), filename: "[name].js", library: "[name]" }, module: { loaders: [ { test: /\.vue$/, loader: 'vue-loader' }, ], } }How to apply more than one conditional style to elements
I have a div that looks like this
<div v-for="person in people"> <p class='name' :class="{people.age == "adult" : 'green'}"></p> </div>I can change the class like that, but I have many age groups (around 8) and I am not sure how this can be done, without putting 8 logical arguments inside the element
VueJS get data as object
Here is a VueJS component:
<template> <a @click="log">click me<a> </template> <script> export default { data() { return { a: "a", b: "something", foo: { bar: "baz" }, // etc. } }, methods: { log() { // console.log( data ); // ??? } } } </script>I want to access the data from the log function and get it as an object (just like in its declaration). I know I can get data like this :
log() { console.log( this.a ); console.log( this.b ); console.log( this.foo ); }But what I want is the whole data as an object (because I want to send the data via an event to a parent component).
Is there a way to get the whole data object inside a method of a component?
How to detect if a website can be embedded as iframe (SAMEORIGIN)
What's a way to detect whether a website can be embedded or not because of the same-origin policy?
I have tried way to detect this but failed. I only found old method. But none of them work now.
V-select bug while selecting elements in Vuejs
I'm building a small application in vuejs 2 where I'm using v-select package for select box, Problem I'm facing is:
I've declared v-select in my component something like this:
<div class="form-group"><label class="col-sm-2 control-label">Company name:</label> <div class="col-sm-6"> <v-select :options="companyOptions" v-model="company_name" :on-search="getOptions" placeholder="Company name"></v-select> </div> </div>So accordingly I'm having data defined as company_name, and I'm calling an axios event to get the searchable data, while the component is being loaded I'm calling index data of first 50 set for initial selection and if anybody types then I'm calling a function getOptions to get data related to the input, now suppose if somebody selects any data and then removes it again from the selection and again search with key press event the searchable data is not displayed, I can see that my axios call is working fine and I'm able to get the relevant data. but it is not displaying in dropdown as it says:
Error in render function: "TypeError: Cannot read property 'label' of null"
Which is coming from the company_name model which was selected. Following is my code in codepen
In this my axios is not working as it says mixed content:
https://codepen.io/anon/pen/Bdeqam?editors=1011' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://connect.stellar-ir.com/api/companies'. This request has been blocked; the content must be served over HTTPS.
So I'm unable to explain properly in this code set. But my code looks same as declared in codepen.
Help me out in this.
Select Multiple on V-Model Object Interaction
VueJS input Validation Push/Pop to Array
Read the link above first.
I asked this question a moment ago and implemented it in a select multiple input instead of a normal select.
The v-model I used is inside an object, let's say form.username instead of form.username.
If I select multiple usernames, the data inside the form.username doesn't get updated, I think it doesn't recognize it as an array.
But instead, if I add a name and an opening and closing bracket after it in the input, let's say , it works.
Not sure if this is intended, just asking here for reference.
Creating Vue Search Bar | How to hide/show data based on input?
I am creating a dynamic search bar that will filter a sidebar full of names based on user input. However, I am having trouble temporarily hiding and showing data based on the search bar's value on keyup. What is the best way to achieve this the "Vue way"?
On keyup, I want to filter through all of the this.people data and only show names that contain the value of the search input.
Below is what my code looks like
Vue.component('sidebar',{ props: ['people', 'tables'], data: () => { return { fullName: '' } }, computed: { computed() { return [this.people, this.tables].join() } }, template: ` <div id="sidebarContain" v-if="this.people"> <input id="sidebar-search" type="text" placeholder="Search..." @keydown="searchQuery"> <select id="sidebar-select" @change="sidebarChanged"> <option value="AZ">A-Z</option> <option value="ZA">Z-A</option> <option value="notAtTable">No Table</option> <option value="Dean's Guest">Dean's Guest</option> <option value="BOO | VIP">BOO | VIP</option> </select> <div v-for="person in people" :class="[{'checked-in': isCheckedIn(person)}, 'person']" :id="person.id" :style="calcRegColor(person)"> <span v-if="person.table_name">{{person.first_name + ' ' + person.last_name + ' - ' + person.table_name}}</span> <span v-else>{{person.first_name + ' ' + person.last_name}}</span> </div> </div> `, methods: { isCheckedIn(person) { return person.reg_scan == null ? true : false; }, isHidden(person) { console.log("here"); }, calcRegColor(person) { switch(person.registration_type) { case "Dean's Guest" : return { color: 'purple' } break; case "BOO | VIP" : return { color: 'brown' } break; case "Student" : return { color: 'green' } break; case "Faculty": case "Staff": return { color: 'blue' } break; case "Alumni Club Leader": return { color: 'gold' } break; case "Table Guest" : return { color: 'pink' } break; default: return { color: 'black' } } } }, watch: { computed() { console.log("People and Tables Available"); } } }); var app = new Vue({ el: '#main', data: { tables: {}, people: [], currentAlerts: [], lastDismissed: [] }, methods: { loadTables() { $.ajax({ method: 'POST', dataType: 'json', url: base_url + 'users/getTableAssignments/' + event_id }).done(data => { this.tables = data; }); }, loadPeople() { $.ajax({ method: 'POST', dataType: 'json', url: base_url + 'users/getParticipants2/' + event_id }).done(data => { this.people = data; this.sortSidebar(this.people); }); }, loadCurrentAlerts() { $.ajax({ method: 'POST', dataType: 'json', url: base_url + 'alerts/getAlerts/' + event_id }).done(data => { this.currentAlerts = data; }); }, loadLastDismissed(num = 15) { $.ajax({ method: 'POST', dataType: 'json', url: base_url + 'alerts/getLastDismissed/' + event_id + '/' + num }).done(data => { this.lastDismissed = data; }); }, setRefresh() { setInterval(() => { console.log("Getting People and Tables"); this.loadPeople(); this.loadTables(); }, 100000); }, makeTablesDraggable() { $(document).on("mouseenter", '.table', function(e){ var item = $(this); //check if the item is already draggable if (!item.is('.ui-draggable')) { //make the item draggable item.draggable({ start: (event, ui) => { console.log($(this)); } }); } }); }, makePeopleDraggable() { $(document).on("mouseenter", '.person', function(e){ var item = $(this); //check if the item is already draggable if (!item.is('.ui-draggable')) { //make the item draggable item.draggable({ appendTo: 'body', containment: 'window', scroll: false, helper: 'clone', start: (event, ui) => { console.log($(this)); } }); } }); } makeDroppable() { $(document).on("mouseenter", ".dropzone, .table", function(e) { $(this).droppable({ drop: function(ev, ui) { console.log("Dropped in dropzone"); } }); }); } }, mounted() { this.loadTables(); this.loadPeople(); this.loadCurrentAlerts(); this.loadLastDismissed(); this.setRefresh(); this.makeTablesDraggable(); this.makePeopleDraggable(); this.makeDroppable(); } <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script> </head> <div id="app"> <sidebar :people="people" :tables="tables"></sidebar> </div>
Adding VueJS attributes to @Html.EditorFor using Razor
I am trying add some VueJS to some existing pages that use Razor syntax.
On this specific page, there is a form that uses the @Html.EditorFor helpers.
I am trying to add a Vue model to this, which works by adding the v-model attribute to an element.
To do this, I tried adding it like so:
@Html.EditorFor(model => model.IsVirtualSubAccount, new { htmlAttributes = new { v_model="isVirtualSubAccount" } })However the v-model is not actually being rendered. The rest of the element comes out fine - in this case it is a checkbox and it appears as normal.
To test this further I added a data-test attribute like so:
@Html.EditorFor(model => model.IsVirtualSubAccount, new { htmlAttributes = new { data_test="renderthis", v_model="isVirtualSubAccount" } })The data-test="renderthis", comes out fine - but I am still missing the v-model:
<input data-test="renderthis" id="IsVirtualSubAccount" name="IsVirtualSubAccount" type="checkbox" value="true" class="check-box">Why is the @Html.EditorFor helper not rendering my Vue syntax?
VueJS input Validation Push/Pop to Array
How can I add items to the hasErrors array if the input username or password are empty and remove them if the input are not empty so that the disabled class on the submit button is dynamically enabled/disabled?
<form> <input type="username" v-model="username"> <input type="password" v-model="password"> <input type="submit" :disabled="hasErrors.length > 0"> </form> <script> var app = new Vue({ el: '#app', data: { username = '', password = '', hasErrors: [] } }); </script>Vue Router Linking Children from Children
I am currently trying to get this thing working with Vue Router.
The goal is: If Nav#1 is clicked, a Component which includes another Router-Link with SubNav#1 preselected should appear.
I could get it to work in the way that if you click Nav#1, the Component with SubNav#1 with an already active class appeared. The problem is that the active class from Nav#1 is removed and it is not possible to navigate to Nav#2 or N#3. If I click on the Router-Link from Nav#2 or #3 nothing happens...
routes.js:
{ path: '/app', component: App, children: [ { path: 'Nav#1', component: Nav#1_Content, children: [ { path: 'SubNav#1', component: SubNav#1_Content}, { path: 'SubNav#2', component: SubNav#2_Content} ]}, { path: 'Nav#2', component: Nav#2_Content}, { path: 'Nav#3', component: Nav#3_Content}, ]}+ custom linkActiveClass in new VueRouter instance.
Nav component:
<router-link to="Nav#1/SubNav#1">Nav #1</router-link> <router-link to="Nav#2">Nav #2</router-link> <router-link to="Nav#3">Nav #3</router-link>Nav#1_Content component:
<template> <div> <nav> <router-link to="SubNav#1" tag="div">SubNav#1</router-link> <router-link to="SubNav#2" tag="div">SubNav#2</router-link> </nav> <router-view></router-view> </div> </template>im using $http.get to get a piece of data, but it gives me an error, im using VueJs
im trying to console.log the response but it gives me an error, i dont know why here is my Script
new Vue({ el: '#app', data: { response:[] }, methods: { get(){ this .$http .get('http://www.asterank.com/api/asterank?query={%22e%22:{%22$lt%22:0.1},%22i%22:{%22$lt%22:4},%22a%22:{%22$lt%22:1.5}}&limit=10') .then(function(response) { console.log(response); }) } } });my html for the trigger
<div id="app"> <button @click="get">GET</button> </div>the error in the console says GET: 500 (INTERNAL SERVER ERROR)
XMLHttpRequest cannot load http://www.asterank.com/api/asterank?query={%22e%22:,%22i%22:,%22a%22:}&limit=10. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500.
Pls Help Thanks
Vue js image selectable
I'm looking to make the img tag selectable. I mean to obtain a boolean value true/false if the photo it's selected or deselected. Any ideas?
<h2 class="headline mb-2 text-xs-center">Choose your hero:</h2> <v-layout row wrap primary-title v-for="hero in heroes" :key="hero.id"> <v-flex xs6> <v-avatar size="80px" class="grey lighten-1"> <img v-bind:src="`${hero.href}`" alt="avatar"> </v-avatar> </v-flex> <v-flex xs6 class="text-xs-right"> <v-subheader>{{hero.name}}€</v-subheader> </v-flex> </v-layout> </v-card> </template> <script> export default { data: () => ({ bases: [{ id: 1, name: "Spiderman", href: "../../static/spiderman.jpg" }, { id: 2, name: "Batman", href: "../../static/batman.jpg" }] }) } </script>How can I pass Vuex data to app components as data?
I know that I can access state of the app from within the components in the app but that means the component is not universal/standalone and it relies on the parent's data/state structure and I think that is wrong.
So I am wondering if I can somehow pass a selected part of the state, that the component represents, to the component as it's data(props?) without the component knowing it comes for the parent state and when the data is updated by the component the app'đ state will reflect this.
So for example if my app's state has data with with 'fields' and each of its values represent a form text field I would build a loop for each of them to create input components and pass/connect data from this 'fields' item into the component. The comonent has no idea where the data comes from or that it represents only a small portion of the whole app. The component only handles the data in its own context.
post request using axios on Laravel 5.5
i'm trying to make some requests using axios and the last Laravel version 5.5 after configure the X-CSRF fields and all my code is simple :
axios.post('/post-contact',{name:'Kamal Abounaim'}) .then((response)=>{ console.log(response) }).catch((error)=>{ console.log(error.response.data) })but i get this error : 419 (unknown status) what the problem supposed to be Thanks for answering
vue.js Uncaught Error: No element option passed to Waypoint constructor
I try to use viewpoint and I Pass the values to my waypoint it send my this message: Uncaught Error: No element option passed to Waypoint constructor,I got my code like this:
in my view galeri.vue :
<template> <div class="play-top" id="final"> <iframe src="xxxxxxxxx" allowfullscreen autoplay="false"></iframe> </div> </template> <script> require('waypoints/lib/jquery.waypoints.min.js') var ele var waypoint = new Waypoint({ element: ele = document.getElementById('final'), handler: function(direction) { if (direction == 'down') { $(ele).addClass('muestra') } else { $(ele).removeClass('muestra') } console.log(direction); } }); <script>any idea what I am doing wrong
Issue using waypoint with vue.js
I am using vue.js and I want to include waypoint in my example it works well this is the original:
html:
<div id="final"> <h2>Mostar el mensaje al pasar por aqui</h2> </div>script:
var ele var waypoint = new Waypoint({ element: ele = document.getElementById('final'), handler: function(direction) { if (direction == 'down') { $(ele).addClass('muestra') } else { $(ele).removeClass('muestra') } console.log(direction); } });css:
.muestra { position: fixed; bottom: 20px; right: 20px; }now a try to use this code in vue.js but it send me this message in the console:
Uncaught ReferenceError: Waypoint is not definedany idea what I am doing wrong this time with vue thi is the code in vue.js like this
galeri.vue:
<template> <div id="final"> <h2>Mostar el mensaje al pasar por aqui</h2> </div> </template> <script> var ele var waypoint = new Waypoint({ element: ele = document.getElementById('final'), handler: function(direction) { if (direction == 'down') { $(ele).addClass('muestra') } else { $(ele).removeClass('muestra') } console.log(direction); } }); </script>Resetting data when property of component change
I built a custom component to which I pass a property.
<template id="friend-component"> <div> {{friend}} <div style="color:red;">{{error}}</div> <br /> <input type="button" v-on:click="addFriend" /> </div> </template> <script> Vue.component('friend', { props: ['friend'], data: function(){ return { error: '' }; }, methods: { addFriend: function () { this.error = 'You already added this friend'; } } }); </script> <friend :friend="selectedFriend"></friend>Then, everytime the parent change the "selectedFriend", I want the data in the child component to be deleted. In this case, it means to delete the error message.
How could I do it?
Note: I figured a way to do it by using a property to store the error instead of the data object. But, Vue is constantly reminding me that I should not modify property...
Mutating a prop locally is now considered an anti-pattern, e.g. declaring a prop and then setting this.myProp = 'someOtherValue' in the component. Due to the new rendering mechanism, whenever the parent component re-renders, the child component’s local changes will be overwritten. Source
How to VueJS router-link active style
My page currently has Navigation.vue component.
I want to make the each navigation hover and active. The 'hover' works but 'active' doesn't.
This is how Navigation.vue file looks like :
And the following is the style.
<style> nav li:hover, nav li:active{ background-color: indianred; cursor: pointer; } </style>This is how hover looks like now and expected exactly same on active.
I would appreciate if you give me an advice for styling router-link active works. Thanks.
Vue selectize, getting json data from option?
I'm using vue2-selectize to display list of options fetched from axios call:
<template> <selectize v-model="selected" :settings="settings"> <option v-for="option in options" :value="option.id"> ({{ option.author }}) - {{ option.description }} </option> </selectize> </template> <script> export default { props: ['old-value'], data() { return { selected: this.oldValue, options: [], settings: { preload: true, placeholder: "Search All Authors", dropdownParent: 'body', closeOnSelect: true, render: { option: function (data) { console.log(data); return '<div>' + data.displayName + '<div class="item-bio">' + data.bio + '</div>'; } }, load: async (query, callback) => { axios.get(route('api.showAllAuthors')).then(response => { this.options = response.data; callback(); }) } }, } }, } </script>The issue is that once you setup the <option> for the select you can only work with the two values it passes to the render function (text and value) and not the original object (whereas the actual <option> has access to this object).
The manual mentions the optional parameter of dataAttr available for <option> tags, but setting <option :data-data="option"> has no effect and I still can't access the original properties.
How can I access the original JSON attributes that the <option> is using in the render function?