I am trying to display all the projects I have coded in my career for my portfolio. I made them into an obj called projects and have mapped through them to render. The problem is that a lot of them are not deployed yet so, for those I want an alert saying "not linked yet" but the link is defaulted to local:3000 and just reloads the page
portfolio: [
{
name: "OmniFood",
description: "",
imgurl: "https://media.giphy.com/media/hvLOGi1KsF02XiZ1DD/giphy.gif",
href: "https://github.io/SbOmniFood/"
},
{
name: "Forkify",
description: "",
imgurl: "https://media.giphy.com/media/ekeOYzzNEpW73RIcSb/giphy.gif",
href: ""
},
{
name: "Connect Four",
description: "",
imgurl: "https://media.giphy.com/media/YrC2lEAcG4loOj2aLI/giphy.gif",
href: ""
},
here is how i render it.
<section id="portfolio">
<h1>Check Out Some of My Projects!</h1>
<div className="portfolioGrid">
{resumeData.portfolio &&
resumeData.portfolio.map(item => {
return (
<a href={`${item.href}`} target="_blank">
<div className="portfolio-item portfolioGridSquare">
<div className="item-wrap">
<div>
<img
src={`${item.imgurl}`}
alt="my projects"
className="item-img"
/>
<div className="overlay">
<div className="portfolio-item-meta">
<h5>{item.name}</h5>
<p>{item.description}</p>
</div>
</div>
</div>
</div>
</div>
</a>
);
})}
<div id="portfolio-wrapper" className=""></div>
</div>
</section>
You should only render a link if the project has a valid href. For example:
const PortfolioList = () => (
<div className="portfolioGrid">
{portfolio.map(item => item.href ? (
<a href={item.href} target="_blank">
<PortfolioItem item={item} />
</a>
) : (
<div onClick={() => alert("not linked yet")}>
<PortfolioItem item={item} />
</div>
))}
</div>
);
const PortfolioItem = ({ item }) => (
<div className="portfolio-item portfolioGridSquare">
<div className="item-wrap">
<div>
<img src={`${item.imgurl}`} alt="my projects" className="item-img" />
<div className="overlay">
<div className="portfolio-item-meta">
<h5>{item.name}</h5>
<p>{item.description}</p>
</div>
</div>
</div>
</div>
</div>
);
Related
im trying to display some images inside a v-for putting the results in the img src=""
<div v-for="piatto in portata" class="card mb-3">
<div class="row">
<div class="col-lg-4">
<img src="'/img/food/' + piatto.img_id + '.jpg'" alt="" style="height:;" class="img-fluid rounded-start img-thumbnail" >
</div>
<div class="col-lg-8">
<div class="card-body mt-3">
<h3 class="card-title">{{piatto.food_name}}</h3>
<h4 class="card-text text-primary">{{piatto.price}}€</h4>
<button type="button" #click="sendOrder(piatto.food_name)" class="btn btn-dark">Aggiungi</button>
</div>
</div>
</div>
</div>
The <img src="'/img/food/' + piatto.img_id + '.jpg'" syntax doesnt seem to work. I dunno if im doing some error in the syntax, or maybe this way of solving the problem is just not viable.
Im pretty new to vue. Thanks in advance
If you are using Webpack
If the images are hosted somewhere on the Internet, you can do that
<template>
<section style="display: flex">
<div v-for="element in elements" :key="element.id" class="">
<img :src="`${imageInitialUrl}${element.imageId}`" />
<p>{{ element.name }}</p>
</div>
</section>
</template>
<script>
export default {
data() {
return {
imageInitialUrl: 'https://source.unsplash.com/random/200x200?sig=',
elements: [
{
id: 1,
name: 'bob',
imageId: '1',
},
{
id: 2,
name: 'patrick',
imageId: '2',
},
{
id: 3,
name: 'sarah',
imageId: '3',
},
],
}
},
}
</script>
This is how it will look.
This is how its written if the images are local
<img :src="require(`#/assets/images/${element.imageId}.jpg`)" />
With this kind of structure
so what I'm trying to achieve is a smooth scroll effect to a particular div on the page when I click a navbar div. I'm currently doing development with react-three-fiber and am using a custom scroll rig component . I am not too sure how to approach this. below can be found my code.
export default function App() {
const [loading, setLoading] = useState(false)
const [background, setBackground] = useState("base")
const phone = useRef()
useEffect(() => {
setTimeout(() => {
setLoading(true)
}, 2600)
}, [])
return (
<>
<Header />
{!loading ? <></> :
<Suspense>
<Canvas id={background} className="canvas-primary" camera={{ position: [0, 0, 5] }} gl={{ powerPreference: "high-performance", alpha: true, antialias: true, stencil: false, depth: true }} shadows >
<ambientLight intensity={0.5} />
<ScrollControls className='scroll-container' pages={15} >
<fog color="#161616" attach="fog" near={8} far={30} />
<BackgroundContext.Provider value={{ background, setBackground }}>
<Scene phone={phone} />
<MouseTracker phone={phone} />
<Physics allowSleep={false} iterations={15} gravity={[0, -200, 0]}>
{/* <Lamp position={[-3, 5, 0]} /> */}
</Physics>
</BackgroundContext.Provider>
<ContactShadows position={[0, -3.1, 0]} scale={10} blur={1.5} far={10} rotation={[Math.PI / 2, 0, 0]} />
<EffectComposer multisampling={15} disableNormalPass={true} >
<DepthOfField focusDistance={0} focalLength={0.02} bokehScae={2} height={480} />
<Bloom luminanceThreshold={0} luminanceSmoothing={10} height={300} opacity={1} />
</EffectComposer>
</ScrollControls>
<Html className="content"><Content /></Html>
</Canvas>
</Suspense>
}
</>
);
}
export default function Header() {
return (
<header className="primary-header">
<div className="middle">
<h1>SYMPHONY</h1>
</div>
<nav className='primary-navigation'>
<ul className="nav-area" >
<li className="item"><div id="About-us" className="link" onClick={() => handleClick(1)}>About Us</div></li>
<li className="item"><div id="D2C" className="link" onClick={() => handleClick(2)}>D2C Marketing</div></li>
<li className="item"><div id="B2B" className="link" onClick={() => handleClick("B2B")}>B2B Marketing</div></li>
<li className="item"><div id="Team" className="link" onClick={() => handleClick(4)}>Our Team</div></li>
</ul>
</nav>
<div id="et_mobile_nav_menu">
<div className="mobile_nav hidden">
<span className="select_page">Select Page</span>
<span className="mobile_menu_bar mobile_menu_bar_toggle"></span>
<ul id="mobile_menu" className="et_mobile_menu" style={{ display: "none" }}><li id="menu-item-377" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-377 et_first_mobile_item">Marketing</li>
<li id="menu-item-376" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-376">Web Design</li>
<li id="menu-item-374" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-374">Resume</li>
<li id="menu-item-378" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-378">Contact</li>
</ul>
</div>
</div>
</header >)
}
function handleClick(link) {
$("#B2B").on('click', function () { //id of the link which is being clicked
console.log(document.getElementsById('ID09'))
$('*').animate({
scrollTop: $("#ID09").offset().top //id of div to be scrolled
}, 1000);
});
}
export default function Content() {
return (
<div className="content">
<div id={"ID00"} >
<div className="Landing-page-content">
<div className="Landing-page-content-inner">
<h1>Your Marketing To The Next Generation</h1>
<h3> 5,000,000+ viewers</h3>
</div>
</div>
</div>
<div id={"ID01"} />
<div id={"ID02"} />
<div id={"ID03"} />
<div id={"ID04"} />
<div id={"ID05"} />
<div id={"ID06"} />
<div id={"ID07"} />
<div id={"ID08"} />
<div id={"ID09"} />
<div id={"ID010"} />
<div id={"ID011"} />
<div id={"ID012"} />
<div id={"ID013"} />
<div id={"ID014"} />
<div id={"ID015"} />
</div>
)
}
So, I have tried multiple approaches to this, the content component is a child to the main canvas which has an in build scrolling, However I am unsure how to manipulate the scroll bar of this particular component through vanilla js or jquery.
I m trying to get product listing specific detail, while I click on the item from the listing page.
I used the react-router-dom navLink approach but failed. kindly guide how can I achieve with or without react-router. "listing to detail" how can I send the whole specific props from listing to detail components
product-listing.js component
<section className='product-listing-sec'>
<div className='container p-0'>
<div className='row'>
<div className='col-12'>
<h1>Category name</h1>
</div>
{/* product card list */}
{/* <ProductCard /> */}
{
data.products.map(prod=>{
return(
<div className='col-12 col-md-6 col-lg-4 col-xl-4' key={prod.title}>
<div className={`product-card ${prod.itemQuantity === 0 ? 'out-stock': ''}`}>
<Link to={{ pathname: `/product-discription`, state:{data:prod.title} }} className='img-wrap'>
<h5>Out of stock</h5>
<img src={prod.image} alt='product image' className='img-fluid' />
<div className='cartbtn'>
<img src={Cartlg} alt='cart' />
</div>
</Link>
<div className='card-detail'>
<p className='title'> {prod.title} </p>
<p className='price'>$ {prod.price} </p>
</div>
</div>
</div>
)
})
}
</div>
</div>
</section>
Product-detail.js page
export const ProductDiscription = (props)=> {
const { data } = props.location
console.log("data :"+ data)
return (<> <div> {data} </div> </>)
}
home.vue
<template>
<app-navbar>
<logo title="navbar"></logo>
<div class="navbar-collapse">
<link href="#first" title="first link"></link>
<link href="#second" title="second link"></link>
<link href="#third" title="third link"></link>
</div>
</app-navbar>
</template>
<script>
export default {
name: "Home",
components: {
AppNavbar: () => import('#/components/navbar.vue')
}
}
</script>
navbar.vue
<script>
export default {
name: "AppNavbar",
props: {
title: {
type: String,
default: "navbarDemo"
},
href: {
type: String,
default: "#"
}
},
template: `
<div class="navbar-container">
<component :is="logo">
<div class="navbar-brand">{{ title }}</div>
</component>
<ul>
<component :is="link">
<li class="item">
<a :href="href" class="link">{{ title }}</a>
</li>
</component
</ul>
</div>
</div>
`
};
</script>
I WANT THIS
<div class="navbar-container">
<div class="navbar-brand">navbar</div>
<div class="navbar-collapse">
<ul>
<li class="item">
first link
</li>
<li class="item">
second link
</li>
<li class="item">
third link
</li>
</ul>
</div>
</div>
What am I doing wrong? Is component used differently? I want to use a component and have another component in it in one file (I don't want to have 20 files here just for navbar). Then compose the structure in this way. Possible?
I'm trying a similar HTML structure as here: link
Here is what you need:
home.vue
<app-navbar :links="links">
<template #logo>
<img src=""/>
</template>
</app-navbar>
data() {
return {
links: [
{ href: '#first", title: 'first link' },
{ href: '#second", title: 'secondlink' },
{ href: '#third", title: 'thirdlink' },
]
}
}
navbar.vue
<template>
<div class="navbar-container">
<div class="navbar-brand">
<slot name="logo" />
</div>
<div class="navbar-collapse">
<ul>
<li v-for="link in links" :key="link.href">
<a :href="link.href">{{ link.title }}</a>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
props: {
links: Array
}
}
</script>
The logo element is passed through a slot (https://fr.vuejs.org/v2/guide/components-slots.html).
You understood <component> wrongly :p <component> do not declare a component, it's only a way to use a component when its name might change.
Instead of writing
<comp1 v-if="test" /> <comp2 v-else /> you could write <component :is="test ? 'comp1" : 'comp2' />. But comp1 and comp2 components still need to be declared somewhere and imported.
Did you check https://v2.vuejs.org/v2/guide/components.html#Dynamic-Components ?
EDIT: If you want to customize links with scoped-slots:
home.vue
<app-navbar :links="links">
<template #logo>
<img src=""/>
</template>
<template #link="{ href, title }">
<a :href="href">{{ title }}</a>
</template>
</app-navbar>
data() {
return {
links: [
{ href: '#first", title: 'first link' },
{ href: '#second", title: 'secondlink' },
{ href: '#third", title: 'thirdlink' },
]
}
}
navbar.vue
<template>
<div class="navbar-container">
<div class="navbar-brand">
<slot name="logo" />
</div>
<div class="navbar-collapse">
<ul>
<li v-for="link in links" :key="link.href">
<slot name="link" :href="link.href" :title="link.title" />
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
props: {
links: Array
}
}
</script>
So the looped links are passed through the slot so the parent is handling the rendering
I have an array of objects, where I have the url of the image. I need to display these images in carousel:
<div class="item active">
<div class="row cst-carouselImg">
<div class="col-sm-3 col-xs-6" ng-repeat="image in pack.hotels.current.hotelImages | limitTo:'4'">
<a href="#"><img
ng-src="<?php
echo 'http://photos.hotelbeds.com/giata/';
?>{{image.path}}"
alt="Image" class="img-responsive"></a>
</div>
</div>
</div>
At this point I have only the first 4 pictures from the array. Next I display the next 4 images from the array:
<div class="item">
<div class="row cst-carouselImg">
<div class="col-sm-3 col-xs-6" ng-repeat="image in pack.hotels.current.hotelImages" ng-if="$index > 3 && $index <8">
<a href="#"><img
ng-src="<?php echo
'http://photos.hotelbeds.com/giata/';
?>{{image.path}}"
alt="Image" class="img-responsive"></a>
</div>
</div>
</div>
How can I display all the images using ng-repeat instead of manually adding <div class="item"> and setting manually $index?
Here i take some sample array you can modify it accordingly
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl',function($scope, $timeout) {
$scope.hotelImages=[{id:1},{id:2},{id:3},{id:4},{id:5},{id:6},{id:7}];
$scope.loopCount=Math.ceil($scope.hotelImages.length/4);
$scope.getNumber = function(num) {
var arr=[];
for(i=0;i<num;i++){
arr.push(i);
}
return arr;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<div class="item" ng-repeat="i in getNumber(loopCount) track by $index">
Carousel :-{{i}}
<div class="row cst-carouselImg">
<div class="col-sm-3 col-xs-6" ng-repeat="image in hotelImages" ng-if="$index >=(i*4) && $index <(i*4)+4" >
image:- {{image.id}}
</div>
</div>
</div>
</div>
If I understood you correctly you are aiming at having a nested ng-repeat, one for the items and one for the images. Let me know if I misunderstood you or you need some clarifications. Please see this snippet below:
var app = angular.module("app", []);
app.controller('exampleCtrl', function($scope){
$scope.hotels= [
[
{
path: "hotel1 path1",
otherprop: true
},
{
path: "hotel1 path2",
otherprop: false
},
{
path: "hotel1 path3",
otherprop: true
}
],
[
{
path: "hotel2 path1",
otherprop: true
},
{
path: "hotel2 path2",
otherprop: true
}
],
[
{
path: "hotel3 path1",
otherprop: false
},
{
path: "hotel3 path2",
otherprop: false
},
{
path: "hotel3 path3",
otherprop: false
},
{
path: "hotel3 path4",
otherprop: true
}
]
];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="exampleCtrl">
<div class="item" ng-repeat="hotel in hotels">
<p>This is Hotel #{{$index+1}}</p>
<div class="row cst-carouselImg">
<div class="col-sm-3 col-xs-6" ng-repeat="image in hotel">
<a href="#">
<img ng-src="{{image.path}}" class="img-responsive" alt="(this is alt text)"/>
Image {{$index+1}}'s path: {{image.path}}
</a>
</div>
</div>
</div>
</div>
</div>