link685 link686 link687 link688 link689 link690 link691 link692 link693 link694 link695 link696 link697 link698 link699 link700 link701 link702 link703 link704 link705 link706 link707 link708 link709 link710 link711 link712 link713 link714 link715 link716 link717 link718 link719 link720 link721 link722 link723 link724 link725 link726 link727 link728 link729 link730 link731 link732 link733 link734 link735 link736 link737 link738 link739 link740 link741 link742 link743 link744 link745 link746 link747 link748 link749 link750 link751 link752 link753 link754 link755 link756 link757 link758 link759 link760 link761 link762 link763 link764 link765 link766 link767 link768 link769 link770 link771 link772 link773 link774 link775 link776 link777 link778 link779 link780 link781 link782 link783 link784 link785 link786 link787 link788 link789 link790 link791 link792 link793 link794 link795 link796 link797 link798 link799 link800 link801 link802 link803 link804 link805 link806 link807 link808 link809 link810 link811 link812 link813 link814 link815 link816 link817 link818 link819 link820 link821

[Vue.js] How to make dropdown for menu items when the count or width exceeds the limits of the menu bar in vue

there is a navigation bar which has the menu items ,which is represented as tabs.

my concern is whenever the menu items exceeds the limit , and excess menu items which doesnt not fit should be moved to a dropdownin menu (showmore) vue

output image

<template>
<div class=”nav”>
<nav class=”navigation”>
<ul>
<li v-for=”(item, index) in groups” :key=”`nav-${index}`“ >
<router-link class=”router-link-
tab”:to=”item.name.toLowerCase()”>{item.name}</router-
link>
</li>
</ul>
</nav>
</div>
</template>

<script>
export default {
name: ‘Tab’,

props: {
back: {
type: Boolean,
default: true,
},
},

</script>

Solution :

There is no easy with of doing it. You can take a look at this example I created for you. You will just need to adjust the css. But this is one way of doing it.

https://codesandbox.io/s/k1oz5vnl4r?fontsize=14

<template>
<div id=”app”>
<nav class=”navigation” ref=”nav”>
<div
style=”display: inline”
v-for=”(item, index) in groups”
:key=”`nav-${index}`“
:ref=”`nav-${index}`“
\>
<router-link
style=”margin: 0 16px”
:to=”item.name.toLowerCase()”
v-if=”maxNavItems == 0 || index < maxNavItems”
\>{item.name}</router-link>
</div>
<select v-model=”selected” ref=”dropdown”>
<option disabled value=”default”>Please select one</option>
<option v-for=”(item, index) in getDropdownItems()” :key=”`nav-${index}`“>{item.name}</option>
</select>
</nav>
</div>
</template>
<script>
export default {
name: “app”,
data: () => ({
groups: [
{ name: “NavItem1” },
{ name: “NavItem2” },
{ name: “NavItem3” },
{ name: “NavItem4” },
{ name: “NavItem5” },
{ name: “NavItem6” },
{ name: “NavItem7” },
{ name: “NavItem8” },
{ name: “NavItem9” },
{ name: “NavItem10” }
],
width: “”,
maxNavItems: 0,
selected: “default”
}),
async mounted() {
await this.$nextTick();
this.width = this.$refs[“nav”].offsetWidth;

let childrenTotalWidth = 0;

for (let i = 0; i < this.$refs[“nav”].children.length; i++) {
const child = this.$refs[“nav”].children[i];
childrenTotalWidth += child.offsetWidth;
if (childrenTotalWidth > this.width) {
this.maxNavItems = i - 1;
break;
}
}
},
methods: {
getDropdownItems() {
const newArr = [];
for (let i = this.maxNavItems; i < this.groups.length; i++) {
newArr.push(this.groups[i]);
}
return newArr;
}
}
};
</script>

<style>

#app {
margin: 60px;
}

.link {
display: inline-block;
padding: 10px;
}

.router-link-active {
color: green;
}
</style>

[Vue.js] Vue list not displaying the keys of a javascript dictionary?

I’m trying to use a v-for element to display the keys of a Javascript dictionary in a list. The dictionary starts blank, but keys and values are added based on a API call. The data is structured something like that below. (I JSON.stringified it to visualize the data, but the original javascript object is a dictionary titled fullFileList.)

fullFileList{
“8-27.TXT.rtf”: {
“textbody”: “Lots of text.”,
“filetitle”: “8-27.TXT.rtf”,
“entities”: [
{
“name”: “Mario Sartori”,
“type”: “Person”
},
{
“name”: “Linda Grey”,
“type”: “Person”
},
{
“name”: “Julia”,
“type”: “Person”
}
]
},
“8-28.TXT.rtf”: {
“textbody”: “Also lots of text.”,
“filetitle”: “8-28.TXT.rtf”,
“entities”: [
{
“name”: “Maine Health Foundation”,
“type”: “Organization”
},
{
“name”: “Grzesiak”,
“type”: “Person”
},
{
“name”: “Jim Williams”,
“type”: “Person”
}
]
}
}

I init the vue.js this way:

var vm = new Vue({
el: ‘#all’,
data: {
files: fullFileList
}
})

And my HTML is like this:

<ul id=”all” class=”nav flex-column nav-pills”>
<li v-for=”(value,key) in files” >
<a class=”nav-link” id=”messages-tab” data-toggle=”tab” role=”tab” aria-controls=”messages” aria-selected=”false”>
{ key } </a>
</li>
</ul>

No list elements appear at any point. What’s going wrong?

EDIT: To clarify, this is a sample of how data is added to the fullFileList dictionary variable:

The original variable is defined like so at the top of the javascript file:

fullFileList = {}

And keys and values are added like this:

basefilename = path.basename(fileNames[loadFile])

fullFileList[basefilename] = {}
fullFileList[basefilename][‘textbody’] = result[‘html’]
fullFileList[basefilename][‘filetitle’] = basefilename

Solution :

You need to make the object assignment valid. You are missing an assignment to the object let fullFileList = … When this is done, the list of files display.

let fullFileList = {
“8-27.TXT.rtf”: {
“textbody”: “Lots of text.”,
“filetitle”: “8-27.TXT.rtf”,
“entities”: [{
“name”: “Mario Sartori”,
“type”: “Person”
},
{
“name”: “Linda Grey”,
“type”: “Person”
},
{
“name”: “Julia”,
“type”: “Person”
}
]
},
“8-28.TXT.rtf”: {
“textbody”: “Also lots of text.”,
“filetitle”: “8-28.TXT.rtf”,
“entities”: [{
“name”: “Maine Health Foundation”,
“type”: “Organization”
},
{
“name”: “Grzesiak”,
“type”: “Person”
},
{
“name”: “Jim Williams”,
“type”: “Person”
}
]
}
}

var vm = new Vue({
el: ‘#all’,
data: {
files: fullFileList
}
})
.as-console-wrapper {display: none !important}
<script src=”https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<ul id=”all” class=”nav flex-column nav-pills”>
<li v-for=”(value,key) in files”>
<a class=”nav-link” id=”messages-tab” data-toggle=”tab” role=”tab” aria-controls=”messages” aria-selected=”false”>
{ key } </a>
</li>
</ul>

Solution 2:

There seems to be an error on fullFileList{} rather fullFileList = {}

You can also make fullFileList an array.

fullFileList = [
{“8-27.TXT.rtf”: {
“textbody”: “Lots of text.”,
“filetitle”: “8-27.TXT.rtf”,
“entities”: [
{
“name”: “Mario Sartori”,
“type”: “Person”
},
{
“name”: “Linda Grey”,
“type”: “Person”
},
{
“name”: “Julia”,
“type”: “Person”
}
]
}
},
{“8-28.TXT.rtf”: {
“textbody”: “Also lots of text.”,
“filetitle”: “8-28.TXT.rtf”,
“entities”: [
{
“name”: “Maine Health Foundation”,
“type”: “Organization”
},
{
“name”: “Grzesiak”,
“type”: “Person”
},
{
“name”: “Jim Williams”,
“type”: “Person”
}
]
}
}
]

[Vue.js] How to replicate 'not in' or 'where' behaviour?

there is a data object in my app called actionsRequired[ACTION_TYPE_DUPLICATES].

And the logic is: v-if=”actionsRequired[ACTION_TYPE_DUPLICATES][reference.id]“, where if the specific reference in the iteration exists in that object, then display the div element.

There’s usually only two duplicates in that property.

I need to display something along the lines of, This reference is the same as Reference 55, please…, and I obviously need to make the 55 dynamic.

I’m wondering if there’s anything in vue.js that is similar/along the lines of something like:

This reference is the same as Reference <span v-where=”actionsRequired[ACTION_TYPE_DUPLICATES][reference.id] !== reference.id”></span>

Any suggestions? Not sure how feasible this would be.

Solution :

How about something like,

<div>This reference is the same as Reference <span v-html=”displayDuplicateReference(reference)”></span></div>

And just write out that custom function to do the “actionsRequired[ACTION_TYPE_DUPLICATES][reference.id] !== reference.id” logic

Solution 2:

Why v-if is not suitable?

<span v-if=”actionsRequired[ACTION_TYPE_DUPLICATES][reference.id] != null
&& actionsRequired[ACTION_TYPE_DUPLICATES][reference.id] !== reference.id”>
This reference … { reference.id }
<span>

[Vue.js] How to get the value from input without using v-model in Vue.js?

There is such an example.When you click on the “add note” button, it checked whether the input is empty or not and adds a block with text entered into the input.

How to make the same example without using v-bind because it does not work in framework7?

Tried to do something like that but it doesn’t work.

et getCat = document.getElementByClassName(‘inputCat’).value;
let newCat = this.getCat;
this.cats.push(this.newCat);
this.newCat = ‘’;
this.saveCats();

A working example with v-model

<f7-block v-for=”(cat, n) in cats”>
<span class=”cat”>{ cat }</span>
<f7-button fill color=”red” @click=”removeCat(n)”></f7-button>
</f7-block>

<f7-list form>
<f7-list-input
class=”inputCat”
v-model=”newCat”
type=”text”
placeholder=””
\></f7-list-input>
<f7-button fill color=”blue” @click=”addCat”> </f7-button>
</f7-list>

export default {
data() {
return{
cats:[],
newCat: null
}
},
mounted() {
if (localStorage.getItem(‘cats’)) {
try {
this.cats = JSON.parse(localStorage.getItem(‘cats’));
} catch(e) {
localStorage.removeItem(‘cats’);
}
}
},
methods: {
addCat() {
// , -
if (!this.newCat) {
return;
}
this.cats.push(this.newCat);
this.newCat = ‘’;
this.saveCats();
},
removeCat(x) {
this.cats.splice(x, 1);
this.saveCats();
},
saveCats() {
const parsed = JSON.stringify(this.cats);
localStorage.setItem(‘cats’, parsed);
}
}
}

Solution :

According to the Framework7 documentation the @input event is used.

export default {
data() {
newCat: null;
}
}
<template>
<f7-list form>
<f7-list-input
class=”inputCat”
:value=”newCat”
@input=”newCat = $event.target.value”
type=”text”
placeholder=””
\></f7-list-input>
<f7-button fill color=”blue” @click=”addCat”> </f7-button>
</f7-list>
</template>

[Vue.js] How to upgrade my global vue-cli install to the latest version?

I already have vue-cli 3.5.5 installed. When I run vue.js create myapp, it shows message Update available 3.6.2.

vue.js CLI v3.5.5

Update available: 3.6.2

How to upgrade vue-cli to the latest version?

When I run npm i -g vue-cli it installs vue-cli version 2.9.6 instead of upgrading the existing vue.js cli version.

OS: Ubuntu 18.04.1.

node version: 10.15.3.

nvm version: 0.34.0.

Solution :

Use the following command to upgrade vue-cli to latest version:

$ npm install -g @vue/cli@latest

Notes

Do not run $ npm i -g vue-cli because vue-cli 3.x is changed to @vue/cli.
The vue-cli update issue states that either npm or yarn can be used to upgrade vue-cli.
However, when working within nvm, the yarn command yarn global add @vue/cli did not work.

[Vue.js] Nativescript vue tooltip use

I’m using nativescript vue

to run this tooltip.

code like in tutorial is not working:

<Button text=”Get Json Data” id=”tool” ref=”tooltip” @tap=”getData” class=”btn btn-primary m-t-20”></Button>

I made button like this and in created trying to make it working but

created() {
let tipref = this.$refs.tooltip;
let tippref = this.$refs.page.tooltip;
//new ToolTip(this.nativeView.topmost().tip,{text:”Text”});
//const tip = new ToolTip(this.nativeView.tipref,{text:”Some Text”});
new ToolTip(tipref,{text:”Some Text”});
},

still not working: TypeError: Cannot read property ‘tooltip’ of undefined
TypeError: Cannot read property ‘nativeView’ of undefined

Can’t figure out how to do it.

The code from the answer How to create a floating help layout? is not working too.

Solution :

In order to access the NativeScript View via ref, you should do this.$refs.tooltip.nativeView. Also wait for the loaded event of the element to make sure it’s ready to use.

<template>
<Page class=”page”>
<ActionBar title=”Home” class=”action-bar”/>
<ScrollView>
<StackLayout class=”home-panel”>
<Button
text=”Get Json Data”
ref=”tooltip”
class=”btn btn-primary m-t-20”
@loaded=”onLoaded”
\></Button>
</StackLayout>
</ScrollView>
</Page>
</template>

<script>
export default {
data() {
return {};
},
methods: {
onLoaded: function(args) {
const ToolTip = require(“nativescript-tooltip”).ToolTip;
const tip = new ToolTip(args.object, {
text: “Some Text”,
backgroundColor: “pink”,
textColor: “black”
});
tip.show();
}
}
};
</script>

[Vue.js] Force refresh of VueTable2 on child component

there is a customer component, and inside of it there is a child component with a vuetable 2. What I need to do is to refresh the table, when I update or create a new customer on parent component.

I was looking to use $emit on parent:

this.$emit(‘CustomerInform’);

In vuetable2 component:

this.$on(‘CustomerInform’, () => {
this.$refs.CustomersTable.refresh();
});

When the table was in the same componen where I made the POST/PUT with “$refs.CustomersTable.refresh()” all was working fine…

Solution :

One way to do it would be to put a ref on the child component inside the parent:

<customers-table ref=”table” />

Then, you will have access to its methods and attributes inside the parent, so you could simply do:

this.$refs.table.$refs.CustomersTable.refresh()

Another way to do it, is to use a global event bus.

EventBus.js:

import vue.js from ‘vue’;
export const EventBus = new Vue();

Parent:

import { EventBus } from EventBus

// …

EventBus.$emit(‘CustomerInform’)

Child:

import { EventBus } from EventBus

// …

created () {
EventBus.$on(‘CustomerInform’, () => {
this.$refs.CustomersTable.refresh();
});
}

[Vue.js] Run function AFTER route fully rendered in Nuxt.js

Background:

I’m building an SSR website using Nuxt. to run a script to fix some typography issues (orphaned text in headers). I can’t do this UNTIL AFTER the DOM is rendered. How can I implement this function once so it runs after each page’s DOM is rendered? It can be either in the Router or in a Nuxt Layout, or elsewhere.

What I’ve tried:

In my layout.vue, Mounted() only runs on the first load (as expected) and adding $nextTick doesn’t seem to affect that. This is even true for generated static pages served from a real webserver.
In my layout.vue, using Vue’s Updated() never seems to fire. I assume this means Nuxt is getting in the way.
Using app.router.afterEach() the function runs on each route change (including first load), but way before the DOM is rendered making it worthless.
If I add Vue.nextTick() into the .afterEach() the function runs on the current page JUST BEFORE the route changes (you can see it flash) but DOES NOT run before that.

What works but seems dumb:

Putting the function in the Mounted() block on each page.

mounted: function(){
this.$nextTick(function () {
const tm = new TypeMate(undefined, { selector: ‘h2, h3, p, li’ });
tm.apply();

})
},

But this seems like a bad idea especially as we add pages. What am I missing? Is there a smart way to do this? Nuxt’s documentation is next to useless for some of this stuff.

Solution :

You can create mixin with mounted function. Lifecycle hooks from mixin will be merged with the lifecycle events and each will be run.

[Vue.js] set opacity for loading overlay

I created a LoadingOverlay component managed by Vuex. The state represents its visibility. The current overlay component uses this code

<template>
<v-dialog value=”true” transition=”false” fullscreen hide-overlay scrollable>
<v-card>
<v-layout justify-center align-center fill-height>
<v-progress-circular :size=”80” :width=”5” indeterminate color=”primary”></v-progress-circular>
</v-layout>
</v-card>
</v-dialog>
</template>

<script>
export default {
name: “LoadingOverlay”
};
</script>

I created an example showing a demo

https://codesandbox.io/s/j7jjrpw83

I would like to setup opacity for the overlay. Currently the background is white and the view gets fully covered. to have an opacity of 0.7 for the overlay background.

Do there is to use my own CSS or is there a ready to use opacity attribute that I can add to the overlay component?

I know I could use color=”transparent” but this would be too much.

Solution :

I’m not too sure if this is the best “Vue” way to do it as I’ve never used Vue, but you can set the color on the v-card to have a translucent background colour:

<v-card color=”rgba(255, 255, 255, 0.7)”>
<v-layout justify-center align-center fill-height>
<v-progress-circular :size=”80” :width=”5” indeterminate color=”primary”></v-progress-circular>
</v-layout>
</v-card>

See fiddle

Or even using style and opacity:

<v-card style=”opacity: 0.7”>
<v-layout justify-center align-center fill-height>
<v-progress-circular :size=”80” :width=”5” indeterminate color=”primary”></v-progress-circular>
</v-layout>
</v-card>

[Vue.js] How to get pagination links in resource collection - Laravel 5.7.19

when working with laravel API resource. when we don’t use any resource collection we get pagination links etc with paginate(10). but when i use Resource::collection i get nothing, just the fields i put in resource.

This is my Controller

return response()->json([
“items” => LatestProjectsResource::collection(Project::has(‘pages’)->where(‘type’, $type)->latest()->paginate(20))
]);

And this is my Resource

public function toArray($request)
{
return [
‘id’ => $this->id,
‘title’ => $this->name,
‘slug’ => $this->slug,
‘url’ => $this->url,
‘thumbnail’ => new ThumbnailResource($this->thumbnail),
];
}

Result

I tried some answers from online community including this Customising Laravel 5.5 Api Resource Collection pagination one but its not working

I tried $this->collection but no luck

Please help me out here.

Solution :

You can get it like

use App\User;
use App\Http\Resources\UserCollection;

Route::get(‘/users’, function () {
return new UserCollection(User::paginate());
});

see documentation

The result will be like

{
“data”: [
{
“id”: 1,
“name”: “Eladio Schroeder Sr.”,
“email”: “therese28@example.com“,
},
{
“id”: 2,
“name”: “Liliana Mayert”,
“email”: “evandervort@example.com“,
}
],
“links”:{
“first”: “http://example.com/pagination?page=1",
“last”: “http://example.com/pagination?page=1",
“prev”: null,
“next”: null
},
“meta”:{
“current_page”: 1,
“from”: 1,
“last_page”: 1,
“path”: “http://example.com/pagination",
“per_page”: 15,
“to”: 10,
“total”: 10
}
}