link2466 link2467 link2468 link2469 link2470 link2471 link2472 link2473 link2474 link2475 link2476 link2477 link2478 link2479 link2480 link2481 link2482 link2483 link2484 link2485 link2486 link2487 link2488 link2489 link2490 link2491 link2492 link2493 link2494 link2495 link2496 link2497 link2498 link2499 link2500 link2501 link2502 link2503 link2504 link2505 link2506 link2507 link2508 link2509 link2510 link2511 link2512 link2513 link2514 link2515 link2516 link2517 link2518 link2519 link2520 link2521 link2522 link2523 link2524 link2525 link2526 link2527 link2528 link2529 link2530 link2531 link2532 link2533 link2534 link2535 link2536 link2537 link2538 link2539 link2540 link2541 link2542 link2543 link2544 link2545 link2546 link2547 link2548 link2549 link2550 link2551 link2552 link2553 link2554 link2555 link2556 link2557 link2558 link2559 link2560 link2561 link2562 link2563 link2564 link2565 link2566 link2567 link2568 link2569 link2570 link2571 link2572 link2573 link2574 link2575 link2576 link2577 link2578 link2579 link2580 link2581 link2582 link2583 link2584 link2585 link2586 link2587 link2588 link2589 link2590 link2591 link2592 link2593 link2594 link2595 link2596 link2597 link2598 link2599 link2600 link2601 link2602

[Vue.js] Having pagination issue in Vue / Laravel

Trying to paginate fetched data in Vue. But having a problem:

Question Updated

Error in render: “TypeError: this.estates.filter is not a function”

Do I missing something?

Pagination.vue

Data(){
return {
meta_data: {
last_page: null,
current_page: 1,
prev_page_url: null
}
}
},
mounted() {
this.fetchEstates();
},
methods: {
fetchEstates(page = 1) {
axios.get(‘/ajax’, {
params: {
page
}).then((response) => {
this.estates = response.data;
this.meta_data.last_page = response.data.last_page;
this.meta_data.current_page = response.data.current_page;
this.meta_data.prev_page_url = response.data.prev_page_url;
});
}
},
computed: {
one: function () {
let filteredStates = this.estates.filter((estate) => {
return (this.keyword.length === 0 || estate.includes(this.keyword)) &&
(this.rooms.length === 0 || this.rooms.includes(estate.rooms)) &&
(this.regions.length === 0 || this.regions.includes(estate.region))});

/// rest of the code….

if you need more information please tell me.

Solution :

You should change the line

this.estates = response.data;

to

this.estates = response.data.data;

Solution 2:

$data = \DB::table(‘allestates’)->paginate(5);
$response = [
‘pagination’ => [
‘total’ => $data->total(),
‘per_page’ => $data->perPage(),
‘current_page’ => $data->currentPage(),
‘last_page’ => $data->lastPage(),
‘from’ => $data->firstItem(),
‘to’ => $data->lastItem()
],
‘data’ => $data
];
return response()->json($response);

[Vue.js] How can I, in Vue, define a local data property that uses a prop as its initial value, in Typescript syntax?

When passing a prop to a child component in Vue, the documentation says:

In addition, every time the parent component is updated, all props in the child component will be refreshed with the latest value. This means you should not attempt to mutate a prop inside a child component. If you do, vue.js will warn you in the console.

The prop is used to pass in an initial value; the child component wants to use it as a local data property afterwards. In this case, its best to define a local data property that uses the prop as its initial value:

props: [‘initialCounter’],
data: function () {
return {
counter: this.initialCounter
}
}

We are using typescript. The syntax for “defining a local data property” is as follows (to my understanding):

<script lang=”ts”>
import vue.js from ‘vue’
import { Component } from ‘vue-property-decorator’

@Component
export default class App extends vue.js {
// Data property
myDataProperty: string;
</script>

And the syntax for a prop is:

@Component
export default class App extends vue.js {
// Makes a “exampleProperty” a component prop with the default value of ‘Example’
@Prop({default: ‘Example’})
exampleProperty: string
}

So, we tried to follow the documentation, and ended up with:

parentComponent.vue

<template>
<childComponent testProperty=’test’ />
</template>

childComponent.vue

<script lang=”ts”>
import { Component, Prop, vue.js } from ‘vue-property-decorator’;

@Component
export default class childComponent extends vue.js {
@Prop(
{
default: ‘notTest’,
validator: (component) => {
return [
‘notTest’,
‘test’,
].indexOf(component) > -1;
},
},
)
testProperty!: string;
testProperty = this.testProperty;
</script>

That, predictably, errored with `Duplicate identifier testProperty.

So, we tried


testProperty!: this.testProperty;

which resulted in

Duplicate identifier ‘testProperty’.
Property ‘testProperty’ has no initializer and is not definitely assigned in the constructor.
Subsequent property declarations must have the same type. Property ‘testProperty’ must be of type ‘this’, but here has type ‘any’.

So, I decided to try the “vue-class-component” decorator.

<script lang=”ts”>
import { Component, Prop, vue.js } from ‘vue-property-decorator’;

@Component({
data: function(){
return {
testProperty: this.testProperty,
}
}
})
export default class childComponent extends vue.js {
@Prop(
{
default: ‘notTest’,
validator: (component) => {
return [
‘notTest’,
‘test’,
].indexOf(component) > -1;
},
},
)
testProperty!: string;
testProperty = this.testProperty;
</script>

This resulted in the error Property ‘testProperty’ does not exist on type ‘Vue’.

I would like to, in a handler, do this.testProperty = ‘newProperty’ at some point, but cannot, because that would be directly modifying a prop.

How can I define a local data property that uses a prop as its initial value in Typescript?

EDIT:

If I do none of the above, and simply define the prop, with no attempt to define a local data property that uses the prop as its initial value, and then do

this.testProperty = ‘test’

in a handler, this error is displayed in the chrome console:

vue.runtime.esm.js[vue.js warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s value. Prop being mutated: “testProperty”

Solution :

I will summarise my comments into a single coherent answer: the problem you are seeing is that you have already defined this.testProperty by declaring it as a prop: doing testProperty = this.testProperty is a circular reference at best. Using the @Prop decorator alone will do the mapping of the attribute in the template to the variable.

<script lang=”ts”>
import { Component, Prop, vue.js } from ‘vue-property-decorator’;

@Component
export default class childComponent extends vue.js {
@Prop(
{
default: ‘notTest’,
validator: (component) => {
return [
‘notTest’,
‘test’,
].indexOf(component) > -1;
},
},
)
testProperty!: string;

// Map prop to local data property
testPropertyLocal = this.testProperty;
</script>

Also, remember this caveat: VueJS properties must be kebab-case in templates and camelCase in JS. So, you need to update the child component reference to:

<template>
<childComponent test-property=’test’ />
</template>

[Vue.js] Validate Fields before submit

How can i Validated a form and then submit?

Button

<v-btn round color=”primary” :disabled=”errors.any()” v-
on:click.prevent=”post”>Submit</v-btn>

Part of my Form

<v-text-field v-model=”signature”
data-vv-name=”signature”
v-validate=”‘required’”
label=”Signature: Enter Fullname”
single-line></v-text-field>
<span v-show=”errors.has(‘signature’)” class=”text-danger”>{
errors.first(‘signature’) }</span>

Part of my method

methods: {
post: function () {
this.$http.post(‘/api/application/‘, {
LastName: this.LastName,
MiddleInitial: this.MiddleInitial

Solution :

It looks like you are using VeeValidate based on the attribute v-validate=”‘required’” being present. Assuming that is installed you can do something as simple as:

<v-btn round color=”primary” :disabled=”errors.any()” v-
on:click.prevent=”validateBeforeSubmit”>Submit</v-btn>

methods: {
validateBeforeSubmit() {
this.$validator.validateAll().then((result) => {
if (result) {
this.post();
return;
}

alert(‘Correct the errors!’);
});
},
post: function () {
this.$http.post(‘/api/application/‘, {
LastName: this.LastName,
MiddleInitial: this.MiddleInitial
});
}
}

more info can be found at: https://baianat.github.io/vee-validate/examples/

[Vue.js] nuxt.js generate stuck at 'generated'

This is my first time building a Nuxt App and I’m trying to deploy it to netlify, now whats happening is I run

yarn run generate

I don’t get any errors or anything but I get stuck here

Built at: 2019-02-01 15:16:38
Asset Size Chunks Chunk Names
53deff7cce1c2de4cfa5.js 59 KiB 1 [emitted] pages_index
server.js 36.9 KiB 0 [emitted] app
server.manifest.json 243 bytes [emitted]
+ 2 hidden assets
Entrypoint app = server.js server.js.map
i Generating pages
15:16:38
Generated /

and then nothing?

The same thing happens when I run the command in my terminal, It just stays on generated and nothing happens

My site is pretty basic and there is not added any other config excpet for the ability to use scss

My site is never deployed Its been sitting like that for an hour is there something I’m doing wrong??

EDIT

Finally something happened

Build exceeded maximum allowed runtime

How can I solve this issue??

Any help would be appreciated!

Solution :

This is actually happening to me, too. Perhaps you have a setInterval call somewhere in the components? It stopped hanging on generate after removing it…

I guess the reason is that when Nuxt starts generating the static pages, it actually runs and renders the vue.js components, so the intervals keep the process alive.

[Vue.js] Async data fetching not updating reactive data property

Ok, guys, Im having a little issue today, all day long, trying to solve, the deal goes like this…

Im fetching some data from firebase to render on the html template with asynchronous functions

there is a fetchList Method that is like this:

async mounted() {
let ret = await this.fetchJobRequireList()
console.log(‘fetchjoblist’ , ret)

async fetchJobRequireList() {
// debugger
let services = JSON.parse(sessionStorage.getItem(‘required_services’))
services != null ? this.required_services = services : null

let docs_ = []
let result = []
if (!services) {
// this.required_services = []
// get required services per user id
let collections = this.$options.firebase.functions().httpsCallable(‘getRequiredServices’)

let docs = await this.$options.firebase.firestore().collection(‘required_services’).get()
// console.log(‘required services docs’, docs)

let _ = this
for (let doc of docs.docs) {

result[doc.id] =
await collections({doc_id: doc.id}).then( async r => {
// debugger
let collections_ = r.data.cols
docs_ = []
_.required_services[doc.id] = []
for (let collection of collections_) {
let path = collection._referencePath.segments

// let documents =
let __ = _
await this.$options.firebase.firestore().collection(path[0])
.doc(path[1]).collection(path[2]).get()
.then(async documents => {
// console.log(‘__documents__‘, documents)
for (let doc_ of documents.docs) {
doc_ = await documents.docs[0].ref.get()
doc_ = {
id: doc_.id,
path: doc_.ref.path,
data: doc_.data()
}
// debugger
__.required_services[doc.id].push(doc_)
console.log(“this?”, this.required_services[doc.id], ‘__??’, __.required_services)
docs_.push(doc_)
}
})
}
console.log(‘__docs__‘, docs_)

return docs_
}).catch(err => console.error(err))

// console.log(‘this.required_services’, this.required_services)
}

}
// console.log(‘object entries’, Object.entries(result))
// console.log(‘__this.required_services__‘, Object.entries(this.required_services))
// sessionStorage.setItem(‘required_services’, JSON.stringify(this.required_services))
return result

}

The expected result would be for the data function properties to be update after the firebase response came, but no update is happening.

If anyone, have any clues, of what could be happening… some people told me that asynchrounous functions could cause problems… but there is no alternative for them, I guess…

Solution :

This line

_.required_services[doc.id] = []

is not reactive. See the first point in the docs

Solution 2:

So as pointed by @StephenThomas, there is some limitations in array change detection capabilities in reactive property usage.
So after loading the content from firebase, try to push it like this.joblist.push(doc) vue.js property will not react properly and make some confusion in the head of someone that doesnt know about this limitation in detecting this kind of array mutation (https://vuejs.org/v2/guide/list.html#Caveats)...
By using this line, now is possible to see the changes in property inside the vue.js dev tools

_.joblist.splice(0,0, local_doc)

Thanks @SthephenThomas, for pointing this out!!

[Vue.js] How can I turn off SSR for only certain pages in Nuxt.js to use them as SPA application?

to develop an application with Nuxt.js that uses SSR for only certain pages (like artist page user page), so the pages without SSR will be used like an SPA. Is it possible to do it using Nuxt.js?

Solution :

You could do that via server middleware

export default function(req, res, next) {
const paths = [‘/‘, ‘/a’]

if (paths.includes(req.originalUrl)) {
// Will trigger the “traditional SPA mode”
res.spa = true
}
// Don’t forget to call next in all cases!
// Otherwise, the app will be stuck forever :|
next()
}

https://blog.lichter.io/posts/selectively-enable-ssr-or-spa-mode-in-a-nuxtjs-ap

Solution 2:

Wrap the contents of the component you don’t want to render server side in a <no-ssr></no-ssr> tag.

@DenisTsoi’s link should give you more information on how it works.

[Vue.js] How to access image from css file on vue

there is css file with class like this

.my-class{
background: url(‘../../assets/images/background/error-bg.jpg’) no-repeat;
}

and I got error on vue.js like this

./src/assets/build/css/style.css (./node_modules/css-loader??ref–6-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref–6-oneOf-1-2!./src/assets/build/css/style.css)
Module not found: Error: Can’t resolve ‘../../assets/images/background/error-bg.jpg’ in ‘/Applications/MAMP/htdocs/twin-track-store/src/assets/build/css’

How I can solve this problem? thanks

Solution :

Add this to the webpack config.

{
test: /\.css$/,
use: [
‘vue-style-loader’,
‘css-loader’
]
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: ‘file-loader’,
options: {
name: ‘[name].[ext]‘,
outputPath: ‘brand/‘,
publicPath: ‘/assets/js/brand/‘,
}
}
]
}

[Vue.js] Trying to create an embed able Vue Component bundled with Laravel Mix

there is created a SPA dashboard using Vue.JS and Laravel, and now would like to create a script that I can use in other sites I manage to just display the event data when creating in the dashboard via the APIs there is made. when using Laravel’s webpack.mix to do my bundling. Thus far, I haven’t really found anything for this situation that explains what I need to do. Any pointers would be helpful, and I can post my code, if I knew what code would be helpful. :)

Solution :

I didn’t entirely understand what you want to do but maybe this project will help. It’s a vue.js Component bundled using Laravel Mix and deployed to npm: https://github.com/niiknow/vue-datatables-net

[Vue.js] What is the best way to store constants in Nuxt?

there is a nuxt project (vuejs) and I’m wondering how to store constants in my project ? ( about 50 constants).

Thank you for the response.
kaboume

Solution :

I use constant.js

const api = “api”;
export default Object.freeze({
api,
});

Solution 2:

I you can create a constants.js file and

// constants.js
export const CONSTANT_1 = ‘CONSTANT_1’;
export const CONSTANT_2 = ‘CONSTANT_2’;
export const CONSTANT_3 = ‘CONSTANT_3’;

// And call it like this
import { CONSTANT_1 } from ‘constants’;

thanks

[Vue.js] Correct way to pass props to all children through slot-scope in Vue.js

Updated code in light of comments about slot-scope

Coming from React, when having a hard time understanding how vue.js uses slots and slot-scope to pass props to child components.

In my current project, there is a DataSlicer component that receives a data prop and performs some manipulation on it. I would then like to pass the manipulated data on to child components via <slot>. I understand that slot-scope is the way to do this but it seems to only work when the parent component tells a child to pass something to its own children — which seems to defeat the whole point (in terms of composition and separation of concerns).

This is what there is working right now, based on reading How to pass props using slots from parent to child -vuejs

App.vue

<DataSlicer
v-if=”data”
y-axis-dimension=”Subparameter”
x-axis-dimension=”Year”
value-dimension=”Total_Registrations”
:filters=”{}”
:data=”data”
\>
<template slot-scope=”childProps”>
<Chart :title=”title” :series-data=”childProps.slicedData” />
</template>
</DataSlicer>

DataSlicer.vue

<template>
<div>
<slot :slicedData=”slicedData”/>
</div>
</template>

My expectation was that I could define slot-scope on the <template> tag in DataSlicer.vue, but that doesn’t seem to work.

Am I missing something? I don’t understand why App.vue.js would need to know or care what DataSlicer is passing to its children. The problem is only compounded the more I split up my components (for example, if I stick DataSlicer inside another component to abstract the api calls, which are currently handled at the App.vue.js level, then App.vue.js also has to also tell that component to pass data on to its DataSlicer child[ren]).

Maybe when just stuck in React thinking here and there’s a different or better way to do this?

EDIT:

If it helps, I’m able to accomplish what using a render function like so:

render: function (createElement) {
return createElement(
‘div’,
this.$slots.default.map(vNode => {
if (vNode.componentOptions) {
vNode.componentOptions.propsData.slicedData = this.slicedData;
}
return vNode;
})
)
}

This feels rather hackish/fragile and also like I’m stretching vue.js to do something in the “react way” when there is probably a better approach.

Solution :

I could not really wrap my head around the code because you didn’t paste the complete code, but this should work this is a working example of slot-scoping in vuejs

//ParentComponent.vue

<template>
<div>
<child-component>
<template scope=”defaultSlotScope”>
<p>{defaultSlotScope.text}</p>
<!– Renders <p>I’ll get rendered inside the default slot.</p> –>
</template>
<template slot=”literally-the-best” scope=”bestSlotScope”>
<p>{bestSlotScope.text}</p>
<!– Renders <p>I’ll get rendered inside the *best* slot.</p> –>
</template>
</child-component>
</div>
</template>

<script>
import ChildComponent from ‘./ChildComponent.vue’;

export default {
components: {
ChildComponent
}
}
</script>

//ChildComponent
<template>
<div>
<p>Look, there’s a slot below me!</p>
<slot :text=”defaultSlotText”></slot>
<slot name=”literally-the-best” :text=”namedSlotText”></slot>
</div>
</template>

<script>
export default {
data() {
return {
defaultSlotText: “I’ll get rendered inside the default slot.”,
namedSlotText: “I’ll get rendered inside the *best* slot.”
}
}
}
</script>

I hope this would help