Software
Vue error in Laravel mix: Uncaught ReferenceError: msg is not defined but it is
I'm new to vue, I'm trying to learn more about it using laravel mix in laravel 5.4, but I got this error in my browser:
app.js:39 Uncaught ReferenceError: msg is not defined at Ut.eval (eval at ei (app.js:40), <anonymous>:2:261) at Ut.t._render (app.js:39) at Ut.<anonymous> (app.js:39) at io.get (app.js:40) at new io (app.js:40) at Ut.Ct.t._mount (app.js:39) at Ut.$mount (app.js:41) at Ut.$mount (app.js:41) at Ut.Mt.t._init (app.js:39) at new Ut (app.js:39)I'm defining my "msg" in my ressources/assests/js/app.js Here's my app.js:
require('./bootstrap'); window.Vue = require('vue'); Vue.component('example', require('./components/Example.vue')); const app = new Vue({ el: '#app', data: { msg: 'a msg' } });
Here's my messages.blade.php
@extends('layouts.app') @section('content') <div class="col-md-12"> <div class="col-md-3 left-sidebar" style="background-color:#fff;"> <h3 align="center"> <div id="app">@{{msg}}</div> </h3> <hr> </div> </div> @endsection
I don't know where the problem might be since I'm new to this, and it's just a simple application. Thanks for helping!
How to loop in vue js
I'm trying to create menu with Vue, but my menu isn't showing up. Here is what i try
<div id="app" class="container"> <b-menu v-for="menu in menu_items" v-bind:data="menu.menu_list" v-bind:key="menu.menu_list"> <label>{{ menu.menu_list }} </label> <b-menu-list v-for="menu_item in menu_items.menu_list" v-bind:data="menu_item" v-bind:key="menu_item.message"> <b-menu-item > {{ menu.message }}</b-menu-item> </b-menu-list> </b-menu> </div>and here is my vue
var App = new Vue({ el: '#app', data: { menu_items: [{ menu_list : 'General' [ { message: 'First Menu' }, { message: 'Second Menu' } ], menu_list : 'Setting' [ { message: 'First Setting Menu' }, { message: 'Second Setting Menu' } ] }] } })Any solution(s) ? sorry for the short question, my english is not good. thanks
my a childcomponent in vue, modify some value inside of it, how to make ti available to parent?
this is my simple component:
<template> <div class="input-group colorpicker-component"> <input type="text" v-model="value" class="form-control"/> <span class="input-group-addon"><i></i></span> </div> </template> <script> export default { props: { value: {type: String}, }, data() { return { } }, mounted: function() { var self = this $(self.$el).colorpicker() }, beforeDestroy: function() { $(this.$el).colorpicker('hide').colorpicker('destroy') } } </script>It gets initiated like this:
<color-picker v-model="imageBackground"></color-picker>How do I get back color that I have picked inside of component back to parent? This component can be used many times in parent.
How can I keep the parent updated with value picked in color-picker component?
How to make SSR render every state using Express or Vue router?
I found a nice SSR (server side rendering) boilerplate with Vue in here : https://github.com/csbun/vue2-ssr-example, right now it can only render pre-defined path from Express
and I need to associate the url path with state it generates, like on this example,
It's already successfully fetch the data API,
But still I couldn't make it to work displaying state change to url. Moreover, the project is complex with Vuex as state manager.
which is better? conditional rendering or computed Properties in vue2?
I am a newbie of vue2. I want to know which is better in below solutions, They get the same result, and why is better.
the first use computed VS the second use v-if, thanks for everyone who watch this question.
How to read the data-* of an element in VueJs?
Hi im trying to learn VueJs
I have 4 buttons with a color, and i try to change the background color of a div according to the button clicked. I'm having trouble reading the data-color object of the button and use it in vue, how do i do this?
My code:
<div id="app"> <div class="container"> <div class="row"> <div class="col-md-3"> <button class="center-block" @click="changeColor" data-color="green">Green</button> </div> <div class="col-md-3"> <button class="center-block" @click="changeColor" data-color="blue">Blue</button> </div> <div class="col-md-3"> <button class="center-block" @click="changeColor" data-color="yellow">Yellow</button> </div> <div class="col-md-3"> <button class="center-block" @click="changeColor" data-color="red">Red</button> </div> </div> <div class="row"> <div class="col-md-12"> <div class="colorblock center-block"> </div> </div> </div> </div> </div> <script src="https://unpkg.com/vue"></script> <script> new Vue({ el: '#app', methods: { changeColor: function() { // Things i tried // console.log(this.data-color); // console.log(this[data-color]); } } }); </script>I'm having a hard time understanding how this works in Vue... Also how do i target .colorblock and change it's css?
Thanks in advance
Uncaught ReferenceError: Vue is not defined when put vue setting in Index.html
i recently learning about vue
I have this file main.js
import Vue from 'vue/dist/vue.js' import Buefy from 'buefy' import 'buefy/lib/buefy.css' Vue.use(Buefy) var App = new Vue({ el: '#app', data: { message : "It's working" } })and here is my html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Vue Example</title> </head> <body> <h3 id="app">{{ message }}</h3> <script src="dist/build.js"></script> <script> </script> </body> </html>It's working. But, now i'm trying to do something with my script. I change main.js (I'm using webpack)
import Vue from 'vue/dist/vue.js' import Buefy from 'buefy' import 'buefy/lib/buefy.css' Vue.use(Buefy)then my index.html to this
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Vue Example</title> </head> <body> <h3 id="app">{{ message }}</h3> <script src="dist/build.js"></script> <script> var App = new Vue({ el: '#app', data: { message:"It's not working" } }) </script> </body> </html>and i get this error
Uncaught ReferenceError: Vue is not defined
How can i fix this ?
Splice out this.index from array between components in VueJS
I have an array of quotes in my parent template which I pass to a child component as a prop. I then take that array and create another child component for each index in the array by passing it through a for loop into a slot. This all seems to work fine.
The problem is that I am trying to delete each index of the array on clicking it's element, but whenever I click an element the first index is deleted, not the index linked to the element clicked.
In the following component I execute method @click and run the method deleteQuote passing the related index.
<template> <div class="panel-body" @click="deleteQuote"> <slot></slot> </div> </template> <script type="text/javascript"> export default{ methods: { deleteQuote() { this.$emit('deleteThisQuote', this.index) } }, props: ['index'] } </script>Since this component doesn't have direct access to my array, I emit a custom event that is listened for in its parent. This triggers another method which splices my array at this.index. Following is the parent component...
<template> <div> <quote-singles class="col-sm-3 panel panel-default" v-for="(quote, index) in quotes" :index="index" @deleteThisQuote="deleteQuote($event)"><h3>{{index}}{{quote}}</h3> </quote-singles> </div> </template> <script type="text/javascript"> import quoteSingles from './quoteSingles.vue' export default{ methods: { deleteQuote(event) { this.quotes.splice(this.event, 1); } }, props: ['quotes'], components: { 'quoteSingles': quoteSingles } } </script>This does everything I want, except it splices out the wrong index in the array. No matter which element I click, myArray[0] is removed. What is going on here? Am i missing something elementary?
Vue.js Webpack dynamic components error during compiling
I am compiling a Vue script with webpack. I am testing dynamic components loading asynchronously, but I get an error during compiling.
Vue.component( 'login-form', () => import('./async v-components/login-form') );I get: Syntax Error: Unexpected token (22:10) pointing to 'i' of 'import'.
webpack.mix.js:
mix.js('resources/assets/js/frontApps.js', 'public/js').extract(['vue']);Any idea why this simple example fails? I followed the guide precisly.
router-link and href not working in Vue js
I am learning vue js and i created an admin page which i am able to route when i am using router-view but when i am trying href or router-link i am not able to load the template thought the url gets changed.
this is my main.js
import Vue from 'vue' import VueResource from 'vue-resource' import VueRouter from 'vue-router' import App from './App.vue' import admin from "./components/admin/admin.vue" import users from "./components/users.vue" Vue.use(VueRouter); Vue.use(VueResource); const router = new VueRouter({ routes: [ {path:'/admin',component:admin}, {path:'/users',component:users}, ] }) new Vue({ el: '#app', router: router, render: h => h(App) })this is my app.vue
this is my app vue file which just want to route to a page via href
<template> <div class = "container" id="app"> <h1>Hi from</h1> <hr> <a href="/api/users">sdsd</a> </div> </template> <script> export default { name: 'app', data(){ return{ users: "" } } } </script> <style> #app { } </style>this is my admin.vue
this the template i want to load in my app.vue its a simple template i want to display in app.vue. its somehow working router-view but it is not working with router-link
<template> <div class="container"> <h1> HI i am routing from admin </h1> </div> </template>the above thing is working via router-view but not thing router-link or href anchor tags............................................................................................................................................................................................
How to edit and update form input values in vue.js?
I am getting up the details in a form for a hotel entry with basic details and viewing it in Room.vue. The created values were displayed here but here i need to give edit option for the filled details. When i click the edit, the page should redirect to RoomsEdit.vue and i should get the filled up contents in that page with form inputs. For that i have tried the following codes but nothing solves my issue.. Kindly have a go through and help me in solving the issue.
Room.vue:
<table class="table table-striped table-hover rooms-table"> <thead> <tr> <td>Title<i class="fa fa-sort"></i></td> <td>Sub Title<i class="fa fa-sort"></i></td> <td> Edit </td> <td> Delete </td> </tr> </thead> <tbody> <tr v-for="room in items"> <td>{{ room.title }}</td> <td>{{ room.subtitle }}</td> <td> <router-link class="btn btn-primary" v-bind:to="'rooms/edit/'+id">Edit</router-link> </td> <td> <button class="btn btn-primary" v-on:click="deleteRoom(room)">Delete</button> </td> </tr> </tbody> </table>Here i am giving edit option and making a redirect to edit page..
RoomsEdit.vue:
<form @submit.prevent="updateItems" class="form-horizontal" enctype="multipart/form-data"> <div class="form-group"> <label for="title" class="col-sm-2 control-label">Title<span class="red">*</span></label> <div class="col-sm-6"> <input type="text" name="title" class="form-control" id="title" v-model="itemsData.title"> <span class="text-danger">{{ errors.title?errors.title[0]:"" }}</span> </div> </div> <div class="form-group"> <label for="subtitle" class="col-sm-2 control-label">Subtitle<span class="red">*</span></label> <div class="col-sm-6"> <input type="text" name="subtitle" class="form-control" id="subtitle" v-model="itemsData.subtitle"> <span class="text-danger">{{ errors.subtitle?errors.subtitle[0]:"" }}</span> </div> </div> </form>Script of RoomsEdit:
<script> import config from '../../../config'; export default { data(){ return{ items: [], itemsData:{ title : '', subtitle : '', }, errors: { } } }, methods:{ fetchRoom(id){ axios.get(config.apiDomain+'/Rooms').then((response)=>this.items = response.data); }, updateItems(e){ axios.put(config.apiDomain+'/Rooms/edit'+this.$route.params.id,this.itemsData).then(response=>{ this.this.itemsData = ""; this.$router.push('/admin/rooms'); }).catch(error=>{ this.errors = error.response.data; }); } }, created: function() { this.fetchRoom(this.$route.params.id); } } </script>RoomsCreate.vue:
<form @submit.prevent="addItems" class="form-horizontal" enctype="multipart/form-data"> <div class="form-group"> <label for="title" class="col-sm-2 control-label">Title<span class="red">*</span></label> <div class="col-sm-6"> <input type="text" name="title" class="form-control" id="title" v-model="itemsData.title"> <span class="text-danger">{{ errors.title?errors.title[0]:"" }}</span> </div> </div> <div class="form-group"> <label for="subtitle" class="col-sm-2 control-label">Subtitle<span class="red">*</span></label> <div class="col-sm-6"> <input type="text" name="subtitle" class="form-control" id="subtitle" v-model="itemsData.subtitle"> <span class="text-danger">{{ errors.subtitle?errors.subtitle[0]:"" }}</span> </div> </div>Script of Rooms.vue:
<script> import config from '../../../config'; export default { data(){ return{ items: [], itemsData:{ title : '', subtitle : '', } } }, methods: { deleteRoom: function (room) { var index = this.items.indexOf(room); this.items.splice(index, 1); } }, mounted() { axios.get(config.apiDomain+'/Rooms').then((response)=>this.items = response.data); } } </script>Script of RoomsCreate.vue:
<script> import config from '../../../config'; export default { data(){ return{ items: [], itemsData:{ title : '', subtitle : '', }, errors: { } } }, methods:{ addItems(){ axios.post(config.apiDomain+'/Rooms',this.itemsData).then(response=>{ this.this.itemsData = ""; this.$router.push('/admin/rooms'); }).catch(error=>{ this.errors = error.response.data; }); } } </script>The issue i am facing is when i click the edit in Room.vue, it redirects to the RoomsEdit.vue where i am not getting the values that was already created, i need to get those value when i go to RoomsEdit.vue there i should edit and update the content.
Alternative folder structure in Laravel
i'm creating a SPA application in Laravel that consists of an API (in PHP) and two applications in VueJS, an Admin Backoffice and a Frontend Web portal.
Ideally i'd like to keep the API in a separate domain like api.mydomain.com but devops told me that couldn't be cause it would mess up their CI structure namely because according to them it's hard to keep everything in sync that way...
So i'm forced to do everything in the same project, now, i don't think that my Vue Routes and stuff and stuff belong in the "resources" directory next to Laravel's translations and Blade views... And using blade views for the "catch-all" route means i cannot use Webpack's HTML plugin, also i think front-end and admin views should have different dependencies and webpack.config files.
So. I'm trying to do the following folder structure
/server |-api (replaces the APP folder) | |--v1/ |---Controllers/ |---Middleware/ |---Repositories |---Traits |---routes.php |--Core(Kernels) |--Models |--Jobs |--Providers | |-bootstrap |-config |-database |-resources(laravel blade views (if any) and translations) |-storage |-tests(phpunit) |-composer.json /admin |-components |-views |--partials/ |-utils |-services |-vuex |-App.vue |-config.js |-main.js |-routes.js |-index.html |-package.json |-webpack.config.jsThe idea is you always need to be routes through Laravel's index.php file and then in the laravel routes i have a catch-all which simply returns Vue's index.html i do this because i need a simple HTML root file in order to be able to take advantage of Webpack HTML plugin What do you guys think about this idea? Feasible? Any better ways of achieving this sort of separation?
define vue component in laravel
I'm using VueJS to load my data in view (using laravel), i do register my components in app.js file, and when i want to use them in one of my blade files it gives me this error :
(unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.)
my app.js file:
require('./bootstrap'); Vue.component('example', require('./components/Example.vue')); const app = new Vue({ el: 'body' }); Vue.component( 'passport-clients', require('./components/passport/Clients.vue') ); Vue.component( 'passport-authorized-clients', require('./components/passport/AuthorizedClients.vue') ); Vue.component( 'passport-personal-access-tokens', require('./components/passport/PersonalAccessTokens.vue') ); Vue.component('employer-enquiry-names', require('./components/Employer/Enquiry/Edit/Names.vue')); Vue.component('employer-enquiry-users', require('./components/Employer/Enquiry/Edit/Users.vue')); Vue.component('employer-enquiry-employer', require('./components/Employer/Enquiry/Edit/Employer.vue'));and here i used my component:
<div class="tab-content" id="enquiry_tabs"> <employer-enquiry-employer ref="employer_enquiry_employer"> </employer-enquiry-employer> <employer-enquiry-users ref="employer_enquiry_users"> </employer-enquiry-users> <div class="tab-pane fade" id="names"> <employer-enquiry-names ref="employer_enquiry_names" > </employer-enquiry-names> </div> </div> <script> var vm = new Vue({ el: '#enquiry_tabs' }); vm.$refs.employer_enquiry_employer.loadData(); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var activatedTab = e.target; // activated tab if (activatedTab.id == "names_link") { vm.$refs.employer_enquiry_names.loadData(); } else if (activatedTab.id == "users_link") { vm.$refs.employer_enquiry_users.loadData(); } else if (activatedTab.id == "employer_link") { vm.$refs.employer_enquiry_employer.loadData(); } }); </script>can anyone help me to resolve this? thanks
GAPI VS Standard HTTP Rest Call
What is the recommended way of connecting to the Google EndPoint API?
Use the Google provided gapi js library - gapi.client.load('helloworld', 'v1', callback, apiRoot);
Call the REST endpoints directly - https://project-id.appspot.com/_ah/api/myapi/v1/users
- Is there a better way?
I'm looking to integrate Google Endpoints with ReactJs or VueJs
source.vue doesn't work in my vue snippet in sublime text3?
I have a very annoying problem with my sublime snippet about .vue type flie.
Say I want to add a vue snippet in sublime on my own, and I want the vue tabtrigger below works in vue type file only.
I add these codes into my vue.sublime-snippet:
After saving this file in my sublime folder, I create a test.vue file and type vue and then press Tab.
But nothing happened. What I expected is Some text could appear after tabbing in test.vue file.
Why doesn't my snippet work on vue file?
PS: I changed source.vue into source.js source.php,etc in my snippet and tested in corresponding js, php file, they all work fine. Only vue didn't work out. Is there anything wrong with sublime identifying vue type file? How to solve this problem?
Recursive components in Vue js
I using vue components to display comments as well as replies to the comments. To display the replies I am simply using comment component recursively. however, I am getting an error.
Here's my code
<template> <div class="box"> <article class="media"> <figure class="media-left"> <p class="image is-64x64"> <img :src="comment.channel.data.imageUrl"> </p> </figure> <div class="media-content"> <div class="content"> <p> <strong><a :href="channelUrl">{{ comment.channel.data.name }}</a></strong> <small>{{ comment.created_at_human }}</small> <br> <p class="is-medium">{{ comment.body }}</p> <nav class="level is-mobile"> <div class="level-left"> <a class="level-item"> <span class="icon is-small"><i class="fa fa-comment-o"></i></span> </a> </div> </nav> </p> </div> </div> </article> <comment v-for="reply in comment.replies.data" :comment="reply" :key="reply.id"></comment> </div>I am getting the following error:
[Vue warn]: Error in render function: "TypeError: Cannot read property 'data' of undefined" found in ---> <Reply> at /home/vagrant/Laravel/youtube/resources/assets/js/components/Comment.vue... (1 recursive calls) <VideoComments> at /home/vagrant/Laravel/youtube/resources/assets/js/components/VideoComments.vue <VideoPlayerLayout> at /home/vagrant/Laravel/youtube/resources/assets/js/components/VideoPlayerLayout.vue <Root>Data is available in the object as I am using fractal to generate json output. Don't really know where am I going wrong.
Manage data array from methods to template syntax Vue
I used foreach to get data array based on id. Initially all went well. But something happen. I think I was wrong using forEach. But after I console.log. My array is fine. Like this :
const Thread = Vue.component('threadpage', function(resolve) { $.get('templates/thread.html').done(function(template) { resolve({ template: template, data : function() { return { data : { title : "Data Table Thread", count : {}, list : {} } }; }, methods : { GetData : function() { var data = {username : "example-username", data : { page : 0, length : 10, schedule : "desc" } }; var args = {"data" : JSON.stringify(data)}; var params = $.param(args); var url = "http://example-url"; var vm = this; DoXhr(url, params, function(response){ count = JSON.parse(response).data.count; vm.data.count = count; var result = []; result_data = JSON.parse(response).data.data; result_data.forEach(function(item) { //console.log(item); result[item._id] = { _id : item._id }; }); vm.data.list = result; console.log(result); }); } }, created : function(){ this.GetData(); } }); }); });As in vuejs.org, I used v-for like this :
<tbody v-for="item in data.list"> <tr> <td> {{ item._id }} </td> </tr> </tbody>The results don't display anything. Something wrong with my template syntax ? Where is my fault ? please help me. Thank you.
Importing a npm module into my javascript file
What is the proper way to import VueJs into my javascript file using NPM? I am getting a Vue is not defined error.
VueJs 2 hide and show DIVs in one html page, is this the right way?
I am building an application but not completely SPA, there are some div's in my page that I want to show and hide them step by step, here is my code :
<div v-if="sectionIs('section1')" class="container"> </div> <div v-if="sectionIs('section2')" class="container"> </div> <div v-if="sectionIs('section3')" class="container"> </div>And in my js file :
var vm = new Vue({ el: '#standard_registeration', data: { section : 'section1', }, computed: { sectionIs: function (sectionName) { return this.section === sectionName } } });I want to know if I'm doing this right, or is there a better approach?
what if I want to add animation later?
Where does `billlable` come from in Laravel Spark's `update-payment-method-stripe` Component?
If Laravel Spark, there's a vue component with the following inline template
<spark-update-payment-method-stripe :user="user" :team="team" :billable-type="billableType" inline-template> /* ... */ <div class="pull-right"> <span v-if="billable.card_last_four"> <i :class="['fa', 'fa-btn', cardIcon]"></i> ************@{{ billable.card_last_four }} </span> </div> /* ... */ </spark-update-payment-method-stripe>This template include the variable billable.card_last_four.
If I track down the definition file for the component, I see this
#File: resources/assets/js/spark-components/settings/payment-method/update-payment-method-stripe.js var base = require('settings/payment-method/update-payment-method-stripe'); Vue.component('spark-update-payment-method-stripe', { mixins: [base] });and if I track down the base component, I see a vue component defined
#File: spark/resources/assets/js/settings/payment-method/update-payment-method-stripe.jsmodule.exports = { props: ['user', 'team', 'billableType'], /* ... */
However, none of these components seem to define billable anywhere. I see a lot of references to this.billable.
#File: spark/resources/assets/js/settings/payment-method/update-payment-method-stripe.js /* ... */ this.form.address = this.billable.billing_address; this.form.address_line_2 = this.billable.billing_address_line_2; this.form.city = this.billable.billing_city; this.form.state = this.billable.billing_state; this.form.zip = this.billable.billing_zip; this.form.country = this.billable.billing_country || 'US'; /* ... */ placeholder() { if (this.billable.card_last_four) { return `************${this.billable.card_last_four}`; } return ''; } /* ... */Where does this billable property come from? I assume Vue's doing some form of meta-programming and/or magic to populate this, but I'm not familiar enough with Vue to know what's going on.