link2055 link2056 link2057 link2058 link2059 link2060 link2061 link2062 link2063 link2064 link2065 link2066 link2067 link2068 link2069 link2070 link2071 link2072 link2073 link2074 link2075 link2076 link2077 link2078 link2079 link2080 link2081 link2082 link2083 link2084 link2085 link2086 link2087 link2088 link2089 link2090 link2091 link2092 link2093 link2094 link2095 link2096 link2097 link2098 link2099 link2100 link2101 link2102 link2103 link2104 link2105 link2106 link2107 link2108 link2109 link2110 link2111 link2112 link2113 link2114 link2115 link2116 link2117 link2118 link2119 link2120 link2121 link2122 link2123 link2124 link2125 link2126 link2127 link2128 link2129 link2130 link2131 link2132 link2133 link2134 link2135 link2136 link2137 link2138 link2139 link2140 link2141 link2142 link2143 link2144 link2145 link2146 link2147 link2148 link2149 link2150 link2151 link2152 link2153 link2154 link2155 link2156 link2157 link2158 link2159 link2160 link2161 link2162 link2163 link2164 link2165 link2166 link2167 link2168 link2169 link2170 link2171 link2172 link2173 link2174 link2175 link2176 link2177 link2178 link2179 link2180 link2181 link2182 link2183 link2184 link2185 link2186 link2187 link2188 link2189 link2190 link2191

[Vue.js] How can I access one attached filter from another in Vue

there is set up a file to hold filters attached to my vue.js object, this is required into my App.js. However there is a filter that would ideally use another filter:

Vue.filter(‘formatDateTime’, value => {
if (value) return moment(String(value)).format(‘DD-MMM-YY hh:mm’)
});
Vue.filter(‘getActivity’, value =>
(!value.lastvisited)
? ‘Not visited yet’
: ‘Last logged in ‘ + Vue.$options.filters.formatDateTime(value.lastvisited)
)

but it can’t reference the global vue.js object, is there a way around this?
I can of course repeat the date formatting code, but I would prefer not to.

Solution :

one option is to seperate definition and global registration

(plus its now usable/importable in non-vue.js context)

// ie. in filters.js
export const formatDateTime = value => value
? moment(String(value)).format(‘DD-MMM-YY hh:mm’)
: null

export const getActivity = value => !value.lastvisited
? ‘Not visited yet’
: ‘Last logged in ‘ + formatDateTime(value.lastvisited)

// ie. in in a filter-global-registration.js
import { getActivity, formatDateTime } from ‘filters.js’

Vue.filter(‘formatDateTime’, formatDateTime);
Vue.filter(‘getActivity’, getActivity)

Solution 2:

What I usually do is create a global reference to the main vue.js object, like:

// Create a filter which calls another filter.
Vue.filter(‘myFilter’, () => {
window.Vue.$options.filters.myOtherFilter(…);
});

// Initialize the main vue.js object.
window.vue.js = new Vue({

});

Then, you should be able to access the filters using window.Vue.$options.filters.myOtherFilter() inside of the filter functions.

It might not be ideal but it has helped me out on several occasions where you have to define plugins/services/components that dont give you the current vue.js instance it uses.

[Vue.js] Vuejs and Laravel How to use http get to pass an array to Laravel controller

I need to pass the array using vue.js http get. But I not sure how to do so.I know I can pass parameter for get method using (when using spatie/laravel-query-builder) ‘/users?filter[name]=John’.

there is an array of category = [10, 20, 100]; the contain of category is id. I need to pass the id to laravel controller.

vue.js to call get

axios.get(url).then((res) => {
console.log(res.data);
})
.catch((err) => console.error(err));

Solution :

You need to JSON.stringify the passed data and assign this string to a get parameter (in this example: myArray).

const data = [{ id: 1 }, { id: 2 }]
const url = ‘https://myendpoint.com'

axios.get(url, {
params: {
myArray: JSON.stringify(data)
}
}).then(res => console.log(res))

[Vue.js] How to get only updated row from database and make app more efficient

I’m creating laravel/vue.js CRUD app and I everything works fine for now but I’m worried about quality of my queries to database after update data.

when using getAllData() each time when I update row in the database. Now, when there is a few records in database is not a problem to ask server each time and render new list in vue.js but in when I will have a few thousands of rows it will make my app slow and heavy.

Now I update database like this:

This is part of my vue.js update function:

updateStatus: function(id){

var index = _.findIndex(this.rows,[“id”,id]);

if (this.rows[index].pay_status==”waiting”){
axios.put(“http://127.0.0.1:8000/api/payments/"+id
,{pay_status:”payed”}).then((response)=>{

this.getAllData();
}

This is my vue.js getAllData function:

getAllData: function(){
axios.get(“http://127.0.0.1:8000/api/payments").then((response)=>{
this.rows = response.data;
});
}

and my PaymentsController:

namespace App\Http\Controllers;

use App\Payments;
use App\Suppliers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Faker\Generator;

class PaymentsController extends Controller
{
public function index()
{
$payments = Payments::with(‘suppliers’)->get();
return response($payments, Response::HTTP_OK);
}
}

my updation function:

public function update(Request $request, $id)
{
$payments = new Payments();
payments::where(‘id’, $id)->update($request->all());
}

Is thare any way to make update in more efficient way, for example get only updated row from database and put it into my existing object with rows? Or maybe i should not worried about it?

Solution :

Without seeing the logic:

the controller can return the record:

return response([‘payment’ => $payment], Response::HTTP_OK);

the axios method can observe that response and then do a replace on the index (just like you did when getting the index previously)

.then((response) => {
const { payment } = response.data;

this.items[index] = payment;
})

As long as items was instantiated in data as an [] then it’s observable.

Solution 2:

If you need updated rows for particular time period.

Also, you can do one thing. When user updating the row u can store the unique ID in new table and you can fetch the data through that ID. and then you can delete that ID from new table when you don’t need latest updated data.

WHILE UPDATING THE ROW via ID

insert id in new table.
update the record.
if need updated record only >> use back-end conditions as per the
requirement >> Fetch id from new table join with main table.
when you don’t need that latest updated record. Delete records from
new table. >> use back-end conditions as per the requirement >>
fetch from main table.

Solution 3:

As @Ohgodwhy said, I change my code like this and now it works fine.

update function

public function update(Request $request, $id)
{
$payments = new Payments();
payments::where(‘id’, $id)->update($request->all());
return response(payments::where(‘id’, $id)->get(), Response::HTTP_OK);
}

axios

updateStatus: function(id){

var index = _.findIndex(this.rows,[“id”,id]);

if (this.rows[index].pay_status==”oczekuje”){
axios.put(“http://127.0.0.1:8000/api/payments/"+id,{pay\_status:"zapacono"}).then((response)=>{
this.rows[index].pay_status=response.data[0].pay_status;
this.waitingInvoices = this.countInvoices();
this.toPay = this.calculatePayment();

});
} else if (this.rows[index].pay_status==”zapacono”){
axios.put(“http://127.0.0.1:8000/api/payments/"+id,{pay\_status:"oczekuje"}).then((response)=>{
this.rows[index].pay_status=response.data[0].pay_status;
this.waitingInvoices = this.countInvoices();
this.toPay = this.calculatePayment();

});
}
},

[Vue.js] Nodejs html pass argument inside img or link source

First of all when new in NodeJS. when trying to phrase arguments inside links and image source but its not working.

\> <!– template.html –> <link rel=”stylesheet” type=”text/css”
\> href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
\> <script src=”https://unpkg.com/axios/dist/axios.min.js"></script>
\> <script src=”https://cdn.jsdelivr.net/npm/vue"></script> <div
\> class=”container” id=”app”>
\> <div class=”row”>
\> <div class=”col-md-6 col-md-offset-3”>
\> <h1>Search</h1>
\> </div>
\> </div>
\> <div class=”row”>
\> <div class=”col-md-4 col-md-offset-3”>
\> <form action=”” class=”search-form”>
\> <div class=”form-group has-feedback”>
\> <label for=”search” class=”sr-only”>Search</label>
\> <input type=”text” class=”form-control” name=”search” id=”search” placeholder=”search” v-model=”query” >
\> <span class=”glyphicon glyphicon-search form-control-feedback”></span>
\> </div>
\> </form>
\> </div>
\> </div>
\> <div class=”row”>
\> <div class=”col-md-3” v-for=”result in results”>
\> <div class=”panel panel-default”>
\> <div class=”panel-heading”>
\> <!– display the city name and country –> <b>TIME:</b> { result._source.frametime }, <b>FROM:</b> {
\> result._source.sourceip } , <img id=”link2”>
\> </div>
\> <div class=”panel-body”>
\> <!– display the latitude and longitude of the city –> <p><b>Destination IP</b>: { result._source.destip }, <b>Destination PORT</b>: { result._source.destporttcp } </p> </br>
\> </div>
\> </div>
\> </div>
\> </div> </div> <!— some styling for the page –> <style>
\> .search-form .form-group {
\> float: right !important;
\> transition: all 0.35s, border-radius 0s;
\> width: 32px;
\> height: 32px;
\> background-color: #fff;
\> box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
\> border-radius: 25px;
\> border: 1px solid #ccc;
\> }
\>
\> .search-form .form-group input.form-control {
\> padding-right: 20px;
\> border: 0 none;
\> background: transparent;
\> box-shadow: none;
\> display: block;
\> }
\>
\> .search-form .form-group input.form-control::-webkit-input-placeholder {
\> display: none;
\> }
\>
\> .search-form .form-group input.form-control:-moz-placeholder {
\> /* Firefox 18- */
\> display: none;
\> }
\>
\> .search-form .form-group input.form-control::-moz-placeholder {
\> /* Firefox 19+ */
\> display: none;
\> }
\>
\> .search-form .form-group input.form-control:-ms-input-placeholder {
\> display: none;
\> }
\>
\> .search-form .form-group:hover,
\> .search-form .form-group.hover {
\> width: 100%;
\> border-radius: 4px 25px 25px 4px;
\> }
\>
\> .search-form .form-group span.form-control-feedback {
\> position: absolute;
\> top: -1px;
\> right: -2px;
\> z-index: 2;
\> display: block;
\> width: 34px;
\> height: 34px;
\> line-height: 34px;
\> text-align: center;
\> color: #3596e0;
\> left: initial;
\> font-size: 14px;
\> } </style>
\>
\> <script> var app = new Vue({
\> el: ‘#app’,
\> // declare the data for the component (An array that houses the results and a query that holds the current search string)
\> data: {
\> results: [],
\> query: ‘’
\> },
\> // declare methods in this vue.js component. here only one method which performs the search is defined
\> methods: {
\> // make an axios request to the server with the current search query
\> search: function() {
\> axios.get(“http://192.168.100.244:3001/search?q=" + this.query)
\> //var strLink = “http://192.168.100.244/images/" + this.query;
\> //document.getElementById(“link2”).setAttribute(“href”,strLink);
\> .then(response => {
\> this.results = response.data;
\>
\> })
\> }
\> },
\> // declare vue.js watchers
\> watch: {
\> // watch for change in the query string and recall the search method
\> query: function() {
\> this.search();
\> }
\> }
\>
\> })
\>
\>
\> </script>

This is my template.html file. I can able to place values from result but when i place argument inside img or link it is not passing through.

Eg: If result._source.url

contains (google.com) , I need to use like <a href=http://{result._source.url}></a>

Any help?

Solution :

let’s try

<a href=`http://${result._source.url}`></a>

if you need pass args :

const http = `${URL}/?ret=${URL_ARGS}`;


<a href={http}>

rgds

[Vue.js] How can i add javascript tag file to Vue

when new with vue.js but i try to import JS script tag to vue.js but it’s not working, please help me and thank you for answer……………

<template>
<div>
<div>
<div class=”bg”>
<div class=”overlay-bg”></div>
<div class=”project-img project-6”></div>
</div>

<div class=”overlay-swipe”>
<div class=”over-1”></div>
<div class=”over-2”></div>
<div class=”over-3”></div>
<div class=”over-4”></div>
<div class=”over-5”></div>

<div class=”over-1-border”></div>
<div class=”over-2-border”></div>
<div class=”over-3-border”></div>
<div class=”over-4-border”></div>
</div>
</div>
</template>

<script src=”assets/homepage/js/plugin.js”></script>
<script src=”assets/homepage/js/fullsreen-showcase.js”></script>
<script src=”assets/homepage/js/main.js”></script>

<style lang=”scss”>
@import “../assets/homepage/awsome/font-awesome-5/css/fontawesome-all.min.css”;
@import “../assets/homepage/css/main.css”;
</style>

Solution :

Well, you could do either one of the following:

<template>
<div>
<!– the template –>
</div>
</template>

<script>
import “assets/homepage/js/plugin.js”;
import “assets/homepage/js/fullsreen-showcase.js”;
import “assets/homepage/js/main.js”;

// Or if those files are modules
// import Something from “assets/homepage/js/plugin.js”;
// …

export default {
// …
}
</script>

Or:

<template>
<div>
<!– the template –>
</div>
</template>

<script src=”assets/homepage/js/main.js”></script>

main.js

Import the rest of the JS files, considering main.js as the entry point.

import “assets/homepage/js/plugin.js”;
import “assets/homepage/js/fullsreen-showcase.js”;

export default {
// …
}

[Vue.js] Display new markers when map bound changed and clear old marker

when map location/bound moved by user, make disappear old position markers and display new position markers.

1. How can I create area(for example if marker locations inside this area then show those and clear rest…

2. Any example for this situation? Or documentation?

For an example you can check this map. Markers are moving every time bounds updated and clearing the old position markers. when exactly trying to do this.

Right now when very at the beginning. Displaying all markers at once on the map.

data(){
return {
map: {},
mapName: “map”,
estates: [],
}
},
mounted() {
axios.get(‘/ajax’).then((response) => {
this.estates = response.data
this.insertMarkers();
});

this.initMap();
window.setTimeout(insertMarkers,3000)

},
methods: {

initMap: function(){

var mapOptions =
{
zoom : 6,
center : {
lat:34.652500,
lng:135.506302
}
};

this.map = new google.maps.Map(document.getElementById(this.mapName), mapOptions);

},

insertMarkers: function() {
this.estates.forEach((estate, index) => {
if(markerStore.hasOwnProperty(estate.id)) {
markerStore[estate.id].setPosition(new google.maps.LatLng({lat: parseFloat(estate.lat), lng: parseFloat(estate.lng)}));
} else {
marker = new google.maps.Marker({
icon: ‘/img/marker.png’,
position: {lat: parseFloat(estate.lat), lng: parseFloat(estate.lng)},
map:map
});

var es_id=estate.id;
google.maps.event.addListener(marker, ‘click’, (function(marker, index,es_id) {
return function() {
console.log(es_id)
window.location.href = “/pages/“ + es_id;
}
})(marker, index,es_id));
markerStore[estate.id] = marker;
}

});
},

Solution :

You need to store old Value and compare with new one you need timeout function to update each time iterval ex window.setTimeout(insertMarkers,3000)

for(var i=0, len=res.length; i<len; i++) {

//Do we have this marker already?
if(markerStore.hasOwnProperty(res[i].driver_id)) {
markerStore[res[i].id].setPosition(new google.maps.LatLng({lat: parseFloat(res[i].lat), lng: parseFloat(res[i].lng)}));
} else {
marker = new google.maps.Marker({
position: {lat: parseFloat(res[i].lat), lng: parseFloat(res[i].lng)},
map:map
});
google.maps.event.addListener(marker, ‘click’, (function(marker, i,id) {
return function() {
console.log(id)
}
})(marker, i,id));

markerStore[res[i].id] = marker;

}
}
markerStore[estate.id] = marker;

}

});

UPDATE

mounted() {
.
.
.

this.initMap();
window.setTimeout(this.insertMarkers,3000)

},
methods: {
.
.
.
insertMarkers: function() {
var marker=[];
var markerStore = {};
this.estates.forEach((estate, index) => {
//Do we have this marker already?
if(markerStore.hasOwnProperty(estate.id)) {
markerStore[estate.id].setPosition(new google.maps.LatLng({lat: parseFloat(estate.lat), lng: parseFloat(estate.lng)}));
} else {
marker = new google.maps.Marker({
icon: ‘/img/marker.png’,
position: {lat: parseFloat(estate.lat), lng: parseFloat(estate.lng)},
map:map
});
var es_id=estate.id;
google.maps.event.addListener(marker, ‘click’, (function(marker, index,es_id) {
return function() {
console.log(es_id)
window.location.href = “/pages/“ + es_id;
}
})(marker, index,es_id));
markerStore[estate.id] = marker;
}

});

[Vue.js] vue cli inspecting css from browser development console

Following various vue.js cli example to successfully implement scss file into the vue.js file, the page now loads with css imported but I cannot inspect from which file / line number the css declaration comes from, all it says in chrome console is within the not from the actual file like “margin.scss line 40”.

here is my vue.config.js

module.exports = {
pluginOptions: {
‘style-resources-loader’: {
preProcessor: ‘scss’,
patterns: [“@/src/css/index.scss”]
}
},

here is my App.vue

<template>
<div >

</div>
</template>

<style lang=”scss” >
@import “./css/index.scss”;
</style>

and here is what I see,

Solution :

Activate sourcemaps:

module.exports = {
css: {
sourceMap: true,
},
pluginOptions: {
‘style-resources-loader’: {
preProcessor: ‘scss’,
patterns: [“@/src/css/index.scss”]
}
},

https://cli.vuejs.org/config/#css-sourcemap

[Vue.js] browserify/vueify inject global scss file in all components

In an app when using browserify and vueify. when trying to inject global scss file (with variables, mixins, colors etc..) into vue.js to make it available for all components (instead to have the file explicitly imported in each components).

there is the following main.scss at path public/app/styles/main.scss:

// public/app/styles/main.scss

// Helpers
@import “helpers/mixins”;
@import “helpers/variables”;
@import “helpers/colors”;

// Base
@import “base/reset”;
@import “base/typography”;
@import “base/base”;

// Layout
@import “base/layout”;

In the gulp.js file there is the following:

// gulp.js

gulp.task(“build_js”, () => {

return browserify({
entries: config.app.index,
cache: {},
dev: true
})
// […]
.transform(vueify, {
sass: {
includePaths: [“public/app/styles”, “public/app/styles/main.scss”]
}
})
// […]

});

This is the App.vue.js component where I’ve tried to use a global defined scss variable:

<!–App.vue–>

<template>

<div id=”app”></div>

</template>

<script>

export default {

name: “App”

}

</script>

<style scoped lang=”scss”>

#app {
width: 100%;
height: 100%;
background-color: $backgroundColor;
}

</style>

But I got the following error:

Error: Undefined variable: “$backgroundColor”. while parsing file: D:\Users\revy\Documents\myapp\public\app\components\App.vue

What am I doing wrong?

Solution :

The issue is that the variable $backgroundColor has not been defined. Most likely, the file that defines it has not been bundled.

You can solve that by importing the main.scss file in the component style block, and it should be resolved.

<!–App.vue–>

<template>

<div id=”app”></div>

</template>

<script>

export default {

name: “App”

}

</script>

<style lang=”scss” src=”public/app/styles/main.scss”></style>
<style scoped lang=”scss”>

@import “public/app/style/main.scss”;

#app {
width: 100%;
height: 100%;
background-color: $backgroundColor;
}

</style>

You might have to change the path, as when not sure what the files structire looks like.

However if the import doesn’t work, You can try including the file directly from the component using a style tag with a src attribute :

<!–App.vue–>

<template>

<div id=”app”></div>

</template>

<script>

export default {

name: “App”

}

</script>

<style lang=”scss” src=”public/app/styles/main.scss”></style>
<style scoped lang=”scss”>

#app {
width: 100%;
height: 100%;
background-color: $backgroundColor;
}

</style>

With this syntax, the bundler will load the SCSS file directly and resolve all the imports within.

[Vue.js] Pass data in vue from single parent component to child components

there is a vue.js component that is page.vue.
And there is a child vue.js component that is card.vue.js as shown below.

I can’t get it to work with injecting data into the card(child) component.

I tried injecting data inside and
in the data function for the page component.

Page.vue

<template>
<div class=”container”>
<card></card>
</div>
</template>

<script>
import Card from “../Card.vue”
export default {
name: ‘skills’,
components: {
“card”: Card
},
data: function() {
return {
message: “Skills”
}
}
}
</script>

Card.vue

<template>
<div class=”container drop-shadow”>
</div>
</template>

<script>
export default {
name: ‘card’,
data: function() {
return {
data: “”,
}
}
}
</script>

that card is reusable from other components also other than Page.vue.
Need to inject data into card respective to where it is displayed.

Solution :

There are two ways that you can pass data down.

The first is through the use of props.

METHOD 1:

<template>
<div class=”container”>
<card :message=”message”></card>
</div>
</template>

<script>
import Card from “../Card.vue”
export default {
name: ‘skills’,
components: {
“card”: Card
},
data: function() {
return {
message: “Skills”
}
}
}
</script>

This will make the data available in Card.vue

<template>
<div class=”container drop-shadow”>{ message }
</div>
</template>

<script>
export default {
name: ‘card’,
props: [‘message’],
data: function() {
return {
data: “”,
}
}
}
</script>

METHOD 2:
You could also put a slot in Card.vue.js which will allow you to put content in between the element tags on the parent like so.
Page.vue

<template>
<div class=”container”>
<card>{ message }</card>
</div>
</template>

<script>
import Card from “../Card.vue”
export default {
name: ‘skills’,
components: {
“card”: Card
},
data: function() {
return {
message: “Skills”
}
}
}
</script>

Card.vue

<template>
<div class=”container drop-shadow”>
<slot />
</div>
</template>

<script>
export default {
name: ‘card’,
data: function() {
return {
data: “”,
}
}
}
</script>

[Vue.js] In Vue.JS method on passed string trim() doesn't work

So when trying to remove white space from one of the returned object’s property with .trim() function but it doesn’t work.

I already tried applying JS functions such as .replace(/\s/g,’’) but it is also not working

<script>
export default {
name: ‘navigation’,
props: [“navigation”],
methods:{
whiteSpace: function(a){
var str = a;
str.toLowerCase();
str.trim();
console.log(str);

return str;
}
}
}
</script>

HTML

<li>
<router-link :to=”{ path: whiteSpace(nav.linkTitle) }”>
{nav.linkTitle}
</router-link>
</li>

It should return string without white space but it doesn’t remove white space.

Solution :

The trim method does not modify the object, it returns a new string.

just return with return str.trim()

Solution 2:

This code:

str.toLowerCase();

returns a new value. It doesn’t modify the current value, so you should have done this:

var str = a;
str = str.toLowerCase();
str = str.trim();
console.log(str);

but any ways, you could just return the trimmed value like so:

export default {
name: ‘navigation’,
props: [“navigation”],
methods: {
whiteSpace: function (a) {
return a.toLowerCase().trim();
}
}
}

Solution 3:

So I found out the problem. .trim() function doesn’t work, I tried .replace(/\s/g, “”); and it helps, thank you for the help guys :)