Hi I am starting with VueJS but I have a problem how to connect IMG src in my template with URL writing in my file JSON .for example when I have some product and I like to show full logo for each article I need to add URL exists in file JSON to src IMG .how I do that please thank
<img src="info.imglogo" alt="Media Aside" />
<span v-text="info.logotitle"></span>
</template>
var infos = [
{
compteur: 1,
imglogo: "../imgs/theme.jpg",
logotitle: "Themeforest",
title: "Thrive Themes",
description:
"Conversion Focused WordPress Themes & Plugins, built from the ground up to make your entire website convert more of your visitors into subscribers, customers & clients.",
link1: "Visit ThriveTheme",
link2: "Read Review",
url: "../imgs/theme.jpg"
},
{
compteur: 2,
logotitle: "Elegant",
title: "Sub-Ex",
description: "com.goodreads.Tres-Zap",
link1: "Dr",
link2: "Honorable",
url: "../imgs/theme.jpg"
},
];
export default {
data() {
return {
infos: infos
};
},
name: "Home",
components: {}
};
</script>
like this.
<template>
<div v-for="(info, index) in infos" :key="index">
<img :src="info.imglogo" alt="Media Aside" v-if="info.imgLogo != undefined" />
<span v-text="info.logotitle"></span>
</div>
</template>
You can do as follow:
<img :src="info.imglogo" alt="Media Aside" />
Explanation:
If you use variables and not text, you have to prepend your HTML attributes by ":"
Here is a working code. Replace your entire vue file by this one:
<template>
<div>
<div v-for="info in infos" :key="info.compteur">
<img :src="info.imglogo" alt="Media Aside" />
<span v-text="info.logotitle"></span>
</div>
</div>
</template>
<script>
export default {
name: "Home",
components: {},
data() {
return {
infos: [
{
compteur: 1,
imglogo: "../imgs/theme.jpg",
logotitle: "Themeforest",
title: "Thrive Themes",
description:
"Conversion Focused WordPress Themes & Plugins, built from the ground up to make your entire website convert more of your visitors into subscribers, customers & clients.",
link1: "Visit ThriveTheme",
link2: "Read Review",
url: "../imgs/theme.jpg",
},
{
compteur: 2,
logotitle: "Elegant",
title: "Sub-Ex",
description: "com.goodreads.Tres-Zap",
link1: "Dr",
link2: "Honorable",
url: "../imgs/theme.jpg",
},
],
};
},
};
</script>
Related
I decided to create a small project in new technology and I choose Gatsby. To let you know I don't work with React and GraphQl before. So thanks to Gatsby I can see also other technologies. So, for now, I try to make an index survey page where the footer and header are modifiable. I take for my backend Contentful and I succeed to do the connection between the content from ContentFul and my component footer. But when I try to do a query in the page index.js impossible to get the data, but they exist (I checked on graphql).
I try to make the query in the component, make the query in a hook and then call the hook. But nothing changes always undefined
In my index.js:
const query = graphql`
query header{
contentfulHeader {
id
titleCard
descriptionCard
logoCard {
file {
url
}
}
}
}
`
const SurveyTitleCard = props => {
return (
<>
<div className="row">
<div className="survey-title card blue-grey darken-3 col s10 offset-s1 m6 offset-m3">
<div className="card-content grey-text text-lighten-3 center-align">
<div className="row logo valign-wrapper">
<div className="col s6 offset-s3 m4 offset-m4">
<img
className="responsive-img"
src=""
alt="logo company"
/>
</div>
</div>
<div className="card-title">
{query.contentfulHeader.titleCard}
</div>
<p>We would love to hear your anonymous thoughts and feedback</p>
</div>
</div>
</div>
</>
)
}
// INDEX PAGE
const IndexPage = () => (
<Layout>
<SEO title="Home" />
<SurveyTitleCard />
</Layout>
)
Here the data from GraphQl:
Here my gatsby-config.js:
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `#AntoineB`,
},
plugins: [
{
resolve: `gatsby-source-contentful`,
options:{
spaceId: `MY_SPACE_ID`,
accessToken: `MY_ACCESS_TOKEN`,
},
},
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
}
See the docs regarding querying data in components using StaticQuery
import React from "react"
import { StaticQuery, graphql } from "gatsby"
export default () => (
<StaticQuery
query={graphql`
query header{
contentfulHeader {
id
titleCard
descriptionCard
logoCard {
file {
url
}
}
}
}
`}
render={data => (
<>
<div className="row">
<div className="survey-title card blue-grey darken-3 col s10 offset-s1 m6 offset-m3">
<div className="card-content grey-text text-lighten-3 center-align">
<div className="row logo valign-wrapper">
<div className="col s6 offset-s3 m4 offset-m4">
<img
className="responsive-img"
src=""
alt="logo company"
/>
</div>
</div>
<div className="card-title">
{data.contentfulHeader.titleCard}
</div>
<p>We would love to hear your anonymous thoughts and feedback</p>
</div>
</div>
</div>
</>
)}
/>
)
I'm using Laravel and Vue for a project I'm working on. Within my dashboard I'm using BootstrapVue's datatable named B-table, which receives JSON data from my API.
The API currently only returns 1 user, however it takes quite some time to load it even though it's just 1 row. I created this GIF to show you it's loading time when refreshing the webpage:
I'm using Axios to receive data from my API, I'm very curious what's causing it to be this slow. Here is my code:
<template>
<div>
<div id="main-wrapper" class="container">
<div class="row">
<div class="col-md-12">
<hr>
<b-table busy.sync="true" show-empty striped hover responsive :items="users" :fields="fields" :filter="filter" :current-page="currentPage" :per-page="perPage" #refreshed="verfris">
<template slot="actions" slot-scope="data">
<a class="icon" href="#"><i class="fas fa-eye"></i></a>
<a class="icon" href="#"><i class="fas fa-pencil-alt"></i></a>
<a class="icon"><i class="fas fa-trash"></i></a>
</template>
</b-table>
<b-pagination :total-rows="totalRows" :per-page="perPage" v-model="currentPage" class="my-0 pagination-sm" />
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
users: [],
filter: null,
currentPage: 1,
perPage: 10,
totalRows: null,
selectedID: null,
fields: [
{
key: 'id',
sortable: true
},
{
key: 'name',
sortable: true
},
{
key: 'email',
sortable: true
},
{
key: 'actions'
}
],
}
},
mounted() {
this.getResults();
},
methods: {
// Our method to GET results from a Laravel endpoint
getResults(ctx, callback) {
axios.get('/api/users')
.then(response => {
this.users = response.data;
this.totalRows = response.data.length;
return this.users;
});
}
},
}
</script>
And the JSON data my API returns:
[
{
"id": 1,
"name": "test",
"email": "user#user.nl",
"email_verified_at": null,
"created_at": "2018-09-28 16:04:36",
"updated_at": "2018-09-28 16:04:36"
}
]
What can I do to solve this loadtime issue?
UPDATE: I'm hosting it on Ubuntu within VirtualBox, maybe it would be important to any of you guys.
UPDATE response time of the request to my API:
From your comment in the post, I guess you already figured out what wrong? i.e. Something is funky about your VirtualBox setup?
I cloned your app and it only took 88ms to load on my Mac.
BTW, your code does not run out of the box. Had to fix and bypass a couple things to get it to run. I would also suggest you install laravel-debugbar to help with debug in laravel.
I'm trying to create a watcher to bind the value from an input run it through a method and display that value on the page. Its a fairly straightforward sample of code I'm working with but I believe I have a scoping issue but I don't see anything wrong.
I tried changing a few things such as the convertTitle function scoping. e.g. But I got the same error
convertTitle() {
return Slug(this.title)
}
My Vue Component -
<template>
<div class="slug-widget">
<span class="root-url">{{url}}</span>
<span class="slug" v-if="slug !== nil">{{slug}}</span>
</div>
</template>
<script>
export default {
props: {
url: {
type: String,
required: true
},
title: {
type: String,
required: true
}
},
data: function() {
return {
slug: this.convertTitle()
}
},
methods: {
convertTitle: function() {
return Slug(this.title)
}
},
watch: {
title: function(val) {
this.slug = this.convertTitle();
}
}
}
</script>
My Blade Partial with input -
#extends('admin.admin')
#section('content')
<div class="row">
<div class="col-md-9">
<div class="row">
<h1>Create new page</h1>
</div>
<div class="row">
<div class="pcard">
<form action="" method="POST" class="">
{{ csrf_field() }}
<label>Title</label>
<input type="text" name="page-title" placeholder="" v-model="title">
<slug-widget url="{{url('/')}}" :title="title"></slug-widget>
</form>
</div>
</div>
</div>
</div>
#endsection
#section('scripts')
<script>
var app = new Vue({
el: '#app',
data: {
title: ''
}
});
</script>
#endsection
Full error Trace -
[Vue warn]: Property or method "title" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
(found in <Root>)
Updated with compute -
export default {
props: {
url: {
type: String,
required: true
},
title: {
type: String,
required: true
}
},
computed: {
slug() {
return Slug(this.title)
}
}
}
The error was resolved by removing the following snippet from app.js
const app = new Vue({
el: '#app'
});
You shouldn't have, and shouldn't ever need, a function call to supply the value of something in your data.
It sounds like you just need to put convertTitle() into a computed and away you go?
I am quite new to Laravel and Vue and I'm currently building an app and trying to incorporate Vue to handle my sidebar navigation items.
Currently my sidebar is populating as expected from my view template. Everything is working great and when I first launch my app, navigation item 0 is selected and highlighted. However, when I click on any other navigation item, I can see the active class being added briefly to that item, but then the new Url loads and my vue template is getting reloaded making navigation item 0 once again active.
I would have thought that only my #yeild( 'content' ) should be reloading and anything sitting in my main blade template should remain unchanged.
Which makes me think I have overlooked something somewhere or have something wrong.
Main blade template:
<body>
<div class="main-wrapper">
<!-- Header -->
#include( 'layouts.header' )
<!-- Sidebar -->
#include( 'layouts.sidebar' )
<!-- Content Wrapper. Contains page content -->
<div #auth class="content-wrapper" #else class="content-wrapper-no_sidebar" #endauth>
<div class="container-fluid">
<!-- Main content -->
<section class="content">
#yield('content')
</section><!-- /.content -->
</div>
</div><!-- /.content-wrapper -->
</div>
...
</body>
layouts.sidebar:
<div id="side_bar">
#auth
<aside class="left-sidebar">
<nav>
<side-bar></side-bar>
</nav>
</aside>
#endauth
</div>
SideMenu.vue (side-bar template file):
<template>
<div class="sidebar-menu">
<a v-for="( item, index ) in items" class="side-nav-item" :class="{ active: item.active }" :href="item.Url" #click="toggleItem( index )">
<i :class="item.Icon"></i><br>
{{ item.Description }}
</a>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
active: false,
Description: 'Dashboard',
Icon: 'fas fa-tachometer-alt',
Url: '/home'
},
{
active: false,
Description: 'Test Cases',
Icon: 'fas fa-calendar-check',
Url: '/testcases'
},
{
active: false,
Description: 'Applications',
Icon: 'fab fa-windows',
Url: '/applications'
},
{
active: false,
Description: 'Testers',
Icon: 'fas fa-users',
Url: '/testers'
},
{
active: false,
Description: 'Modules',
Icon: 'fas fa-sitemap',
Url: '/categories'
}
],
currentActiveIndex: 0,
}
},
methods: {
toggleItem( index ) {
this.items[this.currentActiveIndex].active = false;
this.items[index].active = true;
this.currentActiveIndex = index;
}
},
mounted() {
this.items[this.currentActiveIndex].active = true;
console.log( 'Sidebar Loaded' );
}
}
</script>
app.js:
Vue.component( 'side-bar', require( './components/SideMenu.vue' ) );
// Define new vue instances
const side_bar = new Vue({
el: '#side_bar'
});
I'm trying to bring about a grid with a detail template using declarative initialization. I would appreciate if someone tells me why the details template in the code below is not working. Here's the fiddle I use: http://jsfiddle.net/SiddharthSD2/5MU4r/76/
<div id="demo-grid" data-role="grid"
data-bind="source: people" data-columns='[
{"field": "name",
"title": "Full Name"
},
{"field":"phone", "title":"Phone"}]'
data-details-template="detail-template"
></div>
<script id="detail-template" type="text/x-kendo-template">
<div>
<span>Phone Number for #=name#:</span>
<span data-bind="text: phone" />
<input data-bind="value: phone" />
</div>
</script>
JavaScript
var ds = new kendo.data.DataSource({
data: [
{name: "Joe", phone: "212-555-1234"},
{name: "Sally", phone: "212-999-7785"},
{name: "Bill", phone: "212-244-7035"}
]
});
// Create an observable object.
var vm = kendo.observable({
people: ds,
});
kendo.bind($("#demo-grid"),vm);
It is not data-details-template="detail-template" but data-detail-template="detail-template" (singular detail).
Your JSFiddle modified here http://jsfiddle.net/OnaBai/5MU4r/77/