How to pass AJAX data to the grandchild component - ReactJs - ajax

How can I pass AJAX data from grandparent to grandchild component. It works for grandparent and parent components but for parent and grandchild doesn't in this case
// GrandParent
<main className="main">
<h1 className="main__heading">Images from Unsplash API</h1>
<section className="main__section">
{this.state.posts.map(post => {
return (
<Section imgSrc={post.urls.regular} key={post.id} />
)
})}
</section>
</main>
//Parent
<section className="card-section">
<img className="card-section__img" src={this.props.imgSrc} alt="Lorem Ipsum" />
<Author
authorSrc={post.user.profile_image.small}
authorAlt={post.user.name}
authorName={post.user.name}
/>
</section>
//GrandChild
<div className="author-info">
<img className="author-info__img" src={this.props.authorSrc} alt={this.props.authorAlt} />
<h3 className="author-info__heading">{this.props.authorName}</h3>
</div>

I suppose you need to pass the post data from grandParent to parent and then only forward it to grandChild like
// GrandParent
<main className="main">
<h1 className="main__heading">Images from Unsplash API</h1>
<section className="main__section">
{this.state.posts.map(post => {
return (
<Section post={post} imgSrc={post.urls.regular} key={post.id} />
)
})}
</section>
</main>
//Parent
<section className="card-section">
<img className="card-section__img" src={this.props.imgSrc} alt="Lorem Ipsum" />
<Author
authorSrc={this.props.post.user.profile_image.small}
authorAlt={this.props.post.user.name}
authorName={this.props.post.user.name}
/>
</section>
//GrandChild
<div className="author-info">
<img className="author-info__img" src={this.props.authorSrc} alt={this.props.authorAlt} />
<h3 className="author-info__heading">{this.props.authorName}</h3>
</div>

Related

Vue shared component not showing up

I need some help in debugging a problem that is driving me nuts.
I have a laravel project with Vue3 as the frontend, using InertiaJS for connecting to the backend.
The folder structure is as follows
|_resources
|__js
|___Pages
|____AddContent
|_____Index.vue
|____Home
|_____Index.vue
|___Shared
|____Footer.vue
My Footer.vue (below) is working fine when called at Home/Index.vue
<div class="m-6 text-ternary-dark dark:text-ternary-light text-lg">
<div class="flex justify-between">
<Link href="/">
<i data-feather="home" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i>
</Link>
<Link href="/market"><i data-feather="package" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
<Link href="/add"><i data-feather="plus-square" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
<Link href="/message"><i data-feather="send" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
<Link href="/profile"><i data-feather="user" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
</div>
</div>
</template>
<script>
import { Link } from "#inertiajs/inertia-vue3";
import feather from 'feather-icons';
export default {
components: {
Link,
},
};
</script>
Home.vue
<template>
<Header />
<div class="mb-4 text-ternary-dark dark:text-ternary-light text-lg">
<!-- The top section of homepage, reserved for hastags, news, and other features -->
<div>
<p>Top Component</p>
</div>
<!-- The rest of the homepage contents -->
<div>
<p>The Rest</p>
<div class="wrapper" v-if="blogs.length">
<div class="blog" v-for="blog in blogs" :key="blog">
<Link href="blogs/{id}/show" method="get" :data="{id: blog.id}">
<!-- <img v-bind:src="blog.image"/> -->
<small>posted by: {{ blog.id }}</small>
{{ blog.title }}
</Link>
</div>
</div>
</div>
</div>
<Footer />
</template>
<script>
import { Link } from '#inertiajs/inertia-vue3'
import Header from "../../Shared/Header.vue";
import Footer from "../../Shared/Footer.vue";
export default {
components: {
Header,
Footer,
Link
},
props: {
blogs: Object,
},
};
</script>
Here's the look of Home/Index.vue:
Then, the problem is, at the AddContent/Index.vue (below), I have the same code as the Home/Index.vue to import the footer.
<template>
<div class="mb-4 text-ternary-dark dark:text-ternary-light text-lg">
<form #submit.prevent="submit">
<label for="title">Title: </label>
<input type="text" id="title" v-model="form.title" placeholder="type something" class="rounded-full py-1 px-4"/>
<label for="body">Body: </label>
<input type="text" id="body" v-model="form.body" placeholder="type something" class="rounded-full py-1 px-4"/>
<button type="submit">Submit</button>
</form>
</div>
<Footer />
</template>
<script>
import { reactive } from "vue";
import { Inertia } from "#inertiajs/inertia";
import Footer from "../../Shared/Footer.vue";
export default {
components: {
Footer,
},
setup() {
const form = reactive({
title: null,
body: null,
});
function submit() {
Inertia.post("/", form);
}
return { form, submit };
},
};
</script>
<style scoped>
* {
outline: 1px solid red;
}
</style>
However, in my AddContent/index.vue, the footer bar just does not show up.
I have no idea what the heck is going on... as the red outline was wrapping the footer just fine but nothing from the footer passed to the AddContent page. Any hints on this would be greatly appreciated!
#ShayaUlman suggestion resolved the issue by changing the component into a layout https://inertiajs.com/pages.
For future reference, if your layout does not appear, try to remove or comment out the contents, re-start npm and re-add the contents. This appears to resolve the issue afterwards.

How can i pass data to a modal component in Vuejs. my issue is that it doest not show up at all on the browser

this is the modal
<template>
<div>
<transition name="modal" id="modal-template">
<div class="modal-mask" >
<div class="modal-wrapper">
<div class="modal-container" >
<div class="modal-header">
<slot name="header">
</slot>
</div>
<div class="modal-body" >
<slot name="body">
<h4 style="font-size:18px" class="order-title">
<!-- Productname -->
<h4 >{{items.name}}</h4>/<!-- this is not showing -->
</h4>
</slot>
</div>
</div>
</div>
</div>
</transition>
</div>
</template>
The PARENT VIEW..
<template>
<div class="card">
<div v-bind:key="item.item_id" v-for="item in items" class="card-body">
<!--here i add the v-for to loop through the data but its undefined or empty -->
<div class="row product-order">
<div class="col-sm-12 col-lg-12">
<h4 >{{ item.name }}</h4>
<div class="row">
<div class="image-container">
<div class="col-2 product-info-product-image">
<div v-bind:key="items.item_id" v-for="items in item_id">
<OrderdetailModal
v-if="showModal" #close="showModal = false"/>
</div>
<img
#click="goToProductinfo(item.item_id)"
class="center product-info-product-image"
:src="item.product_image"
/>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
import OrderdetailModal from '../components/Orderdetail';
//beginning of data an methods calls
export default
{
name:"Product",
components:{
OrderdetailModal
},
data () {//here is the data of the parent view
return {
item_id:[],
showModal: false
}
},
methods:{
goToProductinfo(item_id)
{ //here is the function that fetch the data.
this.getProductinfo(item_id);//fetches data and set item_id to response
this.showModal = true;//sets modal to true
}
//end of all methods
//these function should work perfectly
}
}
//end of export default
</script>
//end of code

slick carousel in grid mode cutting off bottom of second row

I'm using slick carousel (http://kenwheeler.github.io/slick/).
I have it set for 2 rows with 3 images per row. The trouble is, the second row is getting cut off right through the middle of each image.
Is this some known bug? Anything I can do?
html:
<div class="slick_slideshow" id="slideshow_houses">
<div>
<img src="img/slideshow_houses/image1.jpg" class="slideshow_houses_image" />
<div class="slick-credit">credit1</div>
</div>
<div>
<img src="img/slideshow_houses/image2.jpg" class="slideshow_houses_image" />
<div class="slick-credit">credit2</div>
</div>
<div>
<img src="img/slideshow_houses/image3.jpg" class="slideshow_houses_image" />
<div class="slick-credit">credit3</div>
</div>
<div>
<img src="img/slideshow_houses/image4.jpg" class="slideshow_houses_image" />
<div class="slick-credit">credit4</div>
</div>
<div>
<img src="img/slideshow_houses/image5.jpg" class="slideshow_houses_image" />
<div class="slick-credit">credit 5 </div>
</div>
<div>
<img src="img/slideshow_houses/image6.jpg" class="slideshow_houses_image" />
<div class="slick-credit">credit 6</div>
</div>
</div>
<!-- end slideshow -->
<div style="clear:both;"></div>
jquery:
$('#slideshow_houses').slick({
rows: 2,
slidesPerRow: 3
});
The code you have looks fine. Going by the comments, you had a div that contained the slideshow that had overflow:hidden. In general, any time you have cut-off content you should check any parent div for overflow:hidden.

BEM naming for wrappers for repeated blocks

I am unsure of the best way to name my BEM blocks, where they require a wrapper.
For example, given the following markup:
<div class="products-list">
<div class="product__item">
<div class="product__item__title">Product 1</div>
<img class="product__item__image" />
</div>
<div class="product__item">
<div class="product__item__title">Product 2</div>
<img class="product__item__image" />
</div>
</div>
I feel that the top wrapper (products-list) is kind of lost.
It's obviously too deep to use something like:
products-list__product__item__image
So, how do we handle wrappers in BEM where the child elements are also wrappers?
With two blocks .product-list and product-item.
<div class="product-list">
<div class="product-list__item product-item">
<div class="product-item__title">Product 1</div>
<img class="product-item__image" />
</div>
<div class="product-list__item product-item">
<div class="product-item__title">Product 2</div>
<img class="product-item__image" />
</div>
</div>
Here the elements .product-list__item share the node with blocks .product-item.
Or, if the CSS rules for your list can be reused in your design, you can rename .product-list to a more generic .list:
<div class="list">
<div class="list__item product-item">
<div class="product-item__title">Product 1</div>
<img class="product-item__image" />
</div>
<div class="list__item product-item">
<div class="product-item__title">Product 2</div>
<img class="product-item__image" />
</div>
</div>

Convert a html div into image

Below is the code that I want to convert to div.
I tried html2canvas but that did not worked somehow.
The div's uppelayer middlerlayer and bottomlayer are one above other making 3 layers.
<div id="container">
<div id="bottomLayer">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSivV5yARSKfCsfaFmdo1Iwc7muglbp92befBPfS7XxglZ0XrpU" id="preview2" />
</div>
<div id="mediumLayer">
<img src="http://f0.pepst.com/c/B7F2F3/402463/ssc3/home/038/amazing.beauties/diana_penty_02_12x92.jpg_480_480_0_64000_0_1_0.jpg" id="preview" />
</div>
<div id="main">
<img src="http://f0.pepst.com/c/B7F2F3/402463/ssc3/home/038/amazing.beauties/diana_penty_02_12x92.jpg_480_480_0_64000_0_1_0.jpg" id="jcrop_target" />
</div>
<div id="upperlayer"><canvas id="canvas2"></canvas></div>
</div>

Resources