Here I am on a project with Nuxt3 javascript and not type script. Nuxt 3 that I discovered as the project progressed, therefore a beginner.
My json package:
{
"name": "frontend",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint:prettier": "prettier --check .",
"lint": "npm run lint:js && npm run lint:prettier",
"lintfix": "prettier --write --list-different . && npm run lint:js -- --fix"
},
"dependencies": {
"@nuxtjs/axios": "^5.13.6",
"@nuxtjs/pwa": "^3.3.5",
"bootstrap": "^4.6.2",
"bootstrap-vue": "^2.22.0",
"core-js": "^3.25.3",
"nuxt": "^2.15.8",
"vue": "^2.7.10",
"vue-server-renderer": "^2.7.10",
"vue-template-compiler": "^2.7.10"
},
"devDependencies": {
"@babel/eslint-parser": "^7.19.1",
"@nuxtjs/eslint-config": "^11.0.0",
"@nuxtjs/eslint-module": "^3.1.0",
"@nuxtjs/style-resources": "^1.2.1",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-nuxt": "^4.0.0",
"eslint-plugin-vue": "^9.5.1",
"fibers": "^5.0.3",
"node-sass": "^8.0.0",
"prettier": "^2.7.1",
"sass-loader": "^10.4.1"
}
}
Project structure: Project structure
Parent file (PagesProject.vue):
<script setup>
import { ref } from 'vue';
import data from '../data/dataProjects.json'
const projects = ref(data)
console.log(data)
</script>
<template lang="">
<div class="structure__pagesProject">
<div v-for="project in projects" :key="project.id" v-bind="project" >
<PortfolioThemProjects :project="project" />
</div>
</div>
</template>
Child file: (ThemProject):
<script setup>
import { ref } from 'vue';
const props = defineProps(['project'])
const img = ref(props.__ob__.value.project.urlImg)
console.log(img.value)
</script>
<template>
<!-- Project start -->
<!-- Structure de la card: -->
<div class="card__structureThemProjects">
<!-- Structure content (image et overlay): -->
<div class="card__content">
<!-- Image: -->
<img
class="card__img"
:src= project.urlImg
alt=""
srcset=""
>
<!-- Overlay: -->
<div class="card__overlay">
<!-- Structure icones sur overlay: -->
<ul class="card__overlay--icone">
<!-- Lien project -->
<li>
<!-- lien description project -->
<!-- <NuxtLink :to="project.linkProject">
<i class="fa-solid fa-circle-info"></i>
</NuxtLink >
-->
</li>
<!-- Lien project -->
<li>
<!-- Lien affiche project -->
<a :href="project.urlProject">
<i class="fa-solid fa-display"></i>
</a>
</li>
</ul>
</div>
</div>
<!-- Structure description -->
<div class="card__description">
<!-- Titre description -->
<h3 class="card__description--title">
{{ project.name }}
</h3>
</div>
</div>
<!-- project end -->
</template>
Json (DataProjects.json):
[
{
"id": "1",
"name": "Réservia",
"class": "reservia",
"urlImg": "../assets/images/Projet_Oc_Reservia_Developpeur-Web.png",
"linkProject": "../ProjectsReservia.vue",
"urlProject": "https://cyrille57.github.io/oc-2-reservia/"
}
]
Problems:
After several tries, change of approach, syntax,
verification, repeatedly, of the relative path, nothing allows displaying
the image in ThemProject.vue
file has the line:
<!-- Image: -->
<img
class="card__img"
:src= project.urlImg
alt=""
srcset=""
>
I put the same images in the public and assets folder, in order to try because I saw here and there what was needed going through one or the other for various reasons but trying the relative path of the two doesn't still does not work.
But if I hard code like:
<img src= "../assets/images/Project_Oc_Reservia_Developer-Web.png"/>
Where:
img src= "../public/images/Project_Oc_Reservia_Developer-Web.png"
works
After maybe I complicate my life or have a bad approach and there is something simpler, but not being an expert I prefer to do with what I understand to date.