Software
script tags inside vue template
there. I am trying to add stripe checkout form through VUE Js template.
<form action="/your-server-side-code" method="POST"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_api_key" data-amount="2000" data-name="1234CPM" data-description="2 widgets" data-image="https://stripe.com/img/documentation/checkout/marketplace.png" data-locale="auto"> </script>But whenever I try to include this form element through vue template, it gives error stating "- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed. ".
It would be very helpful if I could get a way to solve this. Any suggestion would be great. Thank you in advance.
Vue js 1.0 call a method within another method throws 'not a function'
I'm trying to reuse a method within another of my vue js methods like this :-
sendCode: function () { this.showSection("SENDING"); $.ajax({ url: "someurl" + app.searchResponse.Id, type: "POST", contentType: "application/json", success: function (result) { if (result.Success) { this.showSection("SMS SENT"); } else { this.showSection("SMS FAILED"); } }, error: function (error) { console.log(error); this.showSection("SMS FAILED"); } }); }, showSection: function (section) { return app.ui.currentSection = section; }But i get caught Type Error stating this.showSection() is not a function.
VueJS + Laravel 5.4 +Phpstorm bootstrap doesnt work
I have a problem with bootatrap when im using vuejs in laravel 5.4 with phpstorm. Bootstrap styles from sass arent working in example on laravel 5.4 with vuejs on starting.
Firstly had a problem with dev in vue. I installed nodejs and ruby. But still Has no bootstrap in there. Anyone got same issue?
Vue.js: Save index of v-for?
I would like to save the latest index inside a v-for, but I don't know how to include this logic inside the template?
Basically, I have this:
<div v-for="(reply, index) in replies" :key="reply.id">I want to include this logic inside the template somehow:
this.last_index = indexI just want to know the amount of total replies in that v-for loop.
Thank you!
v-if doesn't dynamically change value
I'm working in a Vue.js and I have :
<span v-if="!change[product.id]['name']" v-on:click="show(product.id, 'name')" style="cursor:pointer"> {{{ product.name }}} </span> <span v-if="change[product.id]['name']"> okays </span>I initialise my 'change' with that :
this.$set('products', response.data.products) self.productsLoading=false let array = [] array['name'] = false for (let i = 0; i < response.data.products.length; i++) { self.change[response.data.products[i].id] = array; } console.log(self.change)So my console.log show me the array I want to have so so far so good.
And my show function :
show(id, field){ let array = this.change array[id][field] = true this.$set('change',array) console.log(this.change) },Once more, my console.log is still good when i click on the product.name but I still see the product.name instead of "okays"
VueJS - mouse event doesn't work if element is placed inside Vue app div
In my application, I'd like to use bootstrap-datetimepicker library, which lets you have a date and time picker on the website.
I just put the datepicker in my HTML (some divs and input). I also added the script that initializes the whole thing.
I observed a strange behaviour: if my datetimepicker is placed inside Vue div, it doesn't work! (when I click on the input field, the calendar should be displayed). When I put the picker outside of Vue DIV it works perfectly.
Generally, I noticed that Vue blocks mouse events, i had the same issue with MetricsGraphics.js library (for drawing graphs) - if i put it inside Vue DIV, mouse hover events do not work at all. i had to put it outside of Vue.
What's the reason for that? In case of datetimepicker, I can't put it outside of Vue, because I'd like to use Vue capabilities on it.
I didn't include any code, but basically, this doesn't work:
<div> <div id="vue-app"> <!-- DATE_TIME PICKER: --> <div class="form-group"> <div class='input-group date' id='datetimepicker1'> <input type='text' class="form-control" /> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> <div> <div> <script type="text/javascript"> $(function () { $('#datetimepicker1').datetimepicker(); }); </script>And this works:
<div> <div id="vue-app"> <div> <!-- DATE_TIME PICKER: --> <div class="form-group"> <div class='input-group date' id='datetimepicker1'> <input type='text' class="form-control" /> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> <div> <script type="text/javascript"> $(function () { $('#datetimepicker1').datetimepicker(); }); </script>vuejs with bootstrap and script components
i am using vue.js for developing a single page application and want to know how can i use the jquery part of the bootstrap in vuejs,also want to know about the script tag component of vue like methods,mounted etc. I have tried using bootstrap but i am unable to add the jquery part of my code
How parse data from Carbon Laravel with VUEjs
I return from my backend one Model Object like:
$model = new MyModel(); $meeting->name = "name test n.".rand(0,10000); $meeting->data = Carbon::NOW();Now in my fronted created with VueJs, for property data I have:
{ "date": "2017-07-31 08:03:44.000000", "timezone_type": 3, "timezone": "UTC" }But How Can i parse data from carbon with VueJs with format dd/mm/yyyy ?
Syntax error in IE11 with vue.js, webpack and babel
I'm trying to get a demo to work and it works fine in Chrome but fails in IE11.
The syntax error is related to an eval() but is only an issue with IE11. An example of the issue can be seen here (view with IE11):
Example site not working in IE11.
I have modified the .babelrc file to look like:
{ "presets": [ ["env", { "modules": false, "targets": { "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] } }], "stage-2" ], "plugins": ["transform-runtime"], "env": { "test": { "presets": ["env", "stage-2"], "plugins": ["istanbul"] } } }My webpack.base.conf.js file has been changed to include the babel-polyfill but nothing seems to help fix the issue.
app: ['babel-polyfill', './src/main.js']Any suggestions are much appreciated.
Set the value for <select> without using 'v-model'
I would like to have something that the following Vue template, but it does not work with the property selected. What is the correct property name?
<select :selected="myList"> <option value="abc">ABC</option> </select>As the state is updated in a computed property component does not update
I do not understand what i am doing wrong. I'm using Vuetify framework with nuxt.js on top of vue.js.
I wish that the navigation drawer's initial state to be open on the index page but close on the others. I can manage to have the desired result when i first load the page (if it's the index page the drawer is shown otherwise it's hidden), but when i change the page using the link in the drawer (nuxt js is using vue router in the background) the drawer preserves it's state.
I've made a quick middleware containing this:
export default ({store, route}) => { const mitem = store.state.menu.filter(item => item.to.indexOf(route.name) >= 0 )[0] const title = mitem ? mitem.title : 'Home' store.commit('setPageTitle', title) }here's the store were are the state and mutations (the menu json file contains the entries with the following keys: { title, icon, to })
import menu from '~json/menu.json' export const state = () => ({ menu, drawer: true, pageTitle: undefined }) export const mutations = { toggleDrawer: state => { state.drawer = !state.drawer }, setPageTitle: (state, title) => { state.pageTitle = title state.drawer = title === 'Home' console.log(state.drawer) } }And here's the layout
<template> <v-app> <v-navigation-drawer persistent v-model="drawer" > <v-list> <v-list-tile router v-for="(item, i) in menu" :key="i" :to="item.to" > <v-list-tile-action> <v-icon>{{ item.icon }}</v-icon> </v-list-tile-action> <v-list-tile-content> <v-list-tile-title>{{ item.title }}</v-list-tile-title> </v-list-tile-content> </v-list-tile> </v-list> </v-navigation-drawer> <v-toolbar fixed> <v-toolbar-side-icon @click.native.stop="toggleDrawer" /> <v-toolbar-title>{{ pageTitle }}</v-toolbar-title> <v-spacer></v-spacer> </v-toolbar> <main> <v-container fluid> <nuxt /> </v-container> </main> </v-app> </template> <script> import { mapState, mapMutations } from 'vuex' export default { methods: { ...mapMutations([ 'toggleDrawer' ]) }, computed: { ...mapState([ 'menu', 'drawer', 'pageTitle' ]) } } </script>The console.log shows me that the state get updated, but as the state.drawer changes the component is not updated and the drawer remains present.
Any idea on what i'm doing wrong/how to tackle that issue? Thanks in advance
Seb
How to load default form values into vue object
Below is link to jdfiddle that contains embedded code.
What i want to achieve is to load default form field values into vue object. The form fields do have some default values, but vue make them blank. how can I load the default form values in vue ? ( i cannot embed the values through direct vue object, as values are going to be dynamic, and javascript code will be placed in a special.js file).
how to pass data between different template
I'm trying to make a chat and I do not know how to click an item in one template get the data and transfer it to another. from #template1 to #template2
const app = new Vue({ el: '#content', data:{ users: [], messages: [] } }); template1 <template lang="html"> <li v-on:click="getMessages()"> <div class="content-container"> <span class="name">{{ user.first_name}} {{user.last_name}}</span> <span class="txt"></span> </div> </li> </template> <script> export default { props: ['user'], data: function() { return { messages: [] }; }, methods: { getMessages(id) { this.$http.get('/admin/chat/messages').then(function(res){ this.messages = res.data; } }, } } </script> template2 <template lang="html"> <ul class="chat"> <chat-message v-for="message in messages" :key="+message" :message="message"></chat-message> </ul> </template> <script> export default { props: ['messages'] } </script>how to pass data between this template
Laravel 5.4 Notification Broadcasting
I've set it up with the database, and everything is inserted correctly there. and I am listening correctly with Laravel Echo, and thats being recorded on Pusher, but all my notifications etc are not received by pusher? Can anyone see something I am doing wrong?
My Notification Class<?php namespace App\Notifications; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\BroadcastMessage; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; class RepliedToThread extends Notification { use Queueable; public $thread; /** * Create a new notification instance. * * @return void */ public function __construct($thread) { $this->thread=$thread; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['database','broadcast']; } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ // public function toDatabase($notifiable) // { // return [ // 'thread' => $this->thread, // 'repliedToTime' =>Carbon::now(), // 'user'=>auth()->user() // ]; // } // public function toBroadcast($notifiable) // { // return new BroadcastMessage([ // 'thread' => $this->thread, // 'repliedToTime' =>Carbon::now(), // 'user'=>auth()->user(), // ]); // } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ public function toArray($notifiable) { return [ 'thread' => $this->thread, 'repliedToTime' =>Carbon::now(), 'user'=>auth()->user(), ]; } }
broadcating.phpalthough when this is fired it gets sent to the database but not to pusher. Everything for pusher is setup in my .env file.
<?php return [ /* |-------------------------------------------------------------------------- | Default Broadcaster |-------------------------------------------------------------------------- | | This option controls the default broadcaster that will be used by the | framework when an event needs to be broadcast. You may set this to | any of the connections defined in the "connections" array below. | | Supported: "pusher", "redis", "log", "null" | */ 'default' => "pusher", /* |-------------------------------------------------------------------------- | Broadcast Connections |-------------------------------------------------------------------------- | | Here you may define all of the broadcast connections that will be used | to broadcast events to other systems or over websockets. Samples of | each available type of connection are provided inside this array. | */ 'connections' => [ 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ 'cluster' => 'ap1', 'encrypted' => true ], ], 'redis' => [ 'driver' => 'redis', 'connection' => 'default', ], 'log' => [ 'driver' => 'log', ], 'null' => [ 'driver' => 'null', ], ], ];
.env fileBROADCAST_DRIVER="pusher" PUSHER_KEY="public_key" PUSHER_SECRET="secret_key" PUSHER_APP_ID=app_id
bootstrap.jswindow._ = require('lodash'); /** * We'll load jQuery and the Bootstrap jQuery plugin which provides support * for JavaScript based Bootstrap features such as modals and tabs. This * code may be modified to fit the specific needs of your application. */ try { window.$ = window.jQuery = require('jquery'); require('bootstrap-sass'); } catch (e) {} /** * We'll load the axios HTTP library which allows us to easily issue requests * to our Laravel back-end. This library automatically handles sending the * CSRF token as a header based on the value of the "XSRF" token cookie. */ window.axios = require('axios'); window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; /** * Next we will register the CSRF Token as a common header with Axios so that * all outgoing HTTP requests automatically have it attached. This is just * a simple convenience so we don't have to attach every token manually. */ let token = document.head.querySelector('meta[name="csrf-token"]'); if (token) { window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; } else { console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); } // window.axios.defaults.headers.common = { // // 'X-CSRF-TOKEN': window.Laravel.csrfToken, <-- Comment it out (if you are extending layouts.app file, you won't require this.) // 'X-Requested-With': 'XMLHttpRequest' // }; import Echo from 'laravel-echo'; window.Pusher = require('pusher-js'); window.Echo = new Echo({ broadcaster: 'pusher', key: '################', cluster: 'ap1', encrypted : true }); /** * Echo exposes an expressive API for subscribing to channels and listening * for events that are broadcast by Laravel. Echo and event broadcasting * allows your team to easily build robust real-time web applications. */ // import Echo from 'laravel-echo' // window.Pusher = require('pusher-js'); // window.Echo = new Echo({ // authEndpoint : 'http://localhost/forum_web/public/broadcasting/auth', // broadcaster: 'pusher', // key: '9964dcd35bae49f32d6c', // cluster: 'eu', // encrypted: true, // }); iam used vue2
notification.vue<template> <li class="dropdown" @click="markNotificationAsRead"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <span class="glyphicon glyphicon-globe"></span> Notifications <span class="badge alert-danger">{{unreadNotifications.length}}</span> </a> <ul class="dropdown-menu" role="menu"> <li> <notification-item v-for="unread in unreadNotifications" :unread="unread"></notification-item> </li> </ul> </li> </template> <script> import NotificationItem from './NotificationItem.vue'; export default { props: ['unreads', 'userid'], components: {NotificationItem}, data(){ return { unreadNotifications: this.unreads } }, methods: { markNotificationAsRead() { if (this.unreadNotifications.length) { axios.get('markAsRead'); } } }, mounted() { console.log('Component mounted. asd 1111'); Echo.private('App.User.' + this.userid) .notification((notification) => { console.log(notification); }); } } </script>
VueJS 2 Simplert only covers the component
A brief description is, basically when i click on a "Submit" button per say, an alert should pop out. So I'm using Simplert for Vue to do that.
The project I'm currently doing is a Single Page Application (SPA) so this is where the problem is. The alert only covers the component that I'm in and does not cover the whole page.
Is there a way for the alert to cover the whole page?
Node authentication with client-side routing
So I'm unsure of the practicalities of authentication on a SPA, as I try to get used to my new stack of choice.
I will be serving a Node/Express app, with all API routes on /api, and the frontend served on the root / (all routes will serve index.html, then the client-side routing will take care of the rest. So I have the backend authentication set up with the Passport library, which works well. But how does one keep the server and client sessions in sync? As well as taking care of security.
If I make a POST request to /api/login with credentials, what do I return in the response to the client? And where is the session set?
My frontend is Vue, so I assumed I would just pass the user data (if credentials are correct) to the instance and have a user object. But I'm guessing I need to store a token of some sort? (jwt?)
If someone could clear up how this client-server architecture works, that would be great.
Cheers.
What's the earliest life hook of vue instance that has access to localStorage?
What's the earliest life hook of a vue instance that has access to localStorage and other DOM APIs?
property this.$el undefined on single file component vue js
I'm trying to create a global component using laravel mix with vue js, but when accessing property this.$el it's undefined. Here's my component file:
Datepicker.vue
<template> <input type="text" :name="name" :class="myclass" :placeholder="placeholder" :value="value" /> </template> <script> export default { props: ['myclass','name','placeholder','value'], data () { return { } }, created () { console.log("this.$el", this.$el); //undefined console.log("this", this); //$el is defined var vm = this; var options = { "locale": "es", "onChange": function(selectedDates, dateStr, instance) { vm.$emit('input', dateStr); } }; $(this.$el) // init .flatpickr(options); }, destroyed(){ console.log("destroyed"); } } </script>Vue2 js pass some values from input of one route to another route or share data property from one route to another route
Doing a hotel room booking application in vue2 js. having two screen 1) one gets search input values 2) displays the search result page. see the screen shot below
My route.js is as follows
import FrontEndHome from './components/fontend/Home.vue'; import FrontEndCheck from './components/fontend/Check.vue'; export const routes = [ { path: '/', component: FrontEndHome }, { path: '/check', component: FrontEndCheck } ];What i want is has to get from and to date from first image and has to display those dates in second image.
wwwsqldesigner integration with vue js
I am using SQLDESIGNER plugin for sql schema design, I am trying to integrate this with vue js. I tried to get the xml data from the design, but unable to get that.
Can anyone assist me, to integrate this plugin with vue js also how to map the design xml data with v-model.
Any help would be highly appreciated. Thanks