Vue JS 3 Tutorial for Beginners #9 - Fetching Data

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ส.ค. 2024
  • Hey gang, i this Vue 3 tutorial I'll show you how to fetch data in our components.
    ---- Timestamps ----
    0:00 - Using JSON Server
    7:09 - Fetching data from components
    15:47 - Conditionally showing data
    🐱‍💻 🐱‍💻 BUY THE FULL 20-hr COURSE ON UDEMY:
    www.thenetninja.co.uk/udemy/v...
    🐱‍💻 🐱‍💻 Course Files:
    + github.com/iamshaunjp/Vue-3-F...
    🐱‍👤🐱‍👤 JOIN THE GANG -
    / @netninja
    🐱‍💻 🐱‍💻 My Udemy Courses:
    + Modern JavaScript - www.thenetninja.co.uk/udemy/m...
    + Vue JS & Firebase - www.thenetninja.co.uk/udemy/v...
    + D3.js & Firebase - www.thenetninja.co.uk/udemy/d...
    🐱‍💻 🐱‍💻 Helpful Links:
    + HTML & CSS Course - • HTML & CSS Crash Cours...
    + Get VS Code - code.visualstudio.com/
    🐱‍💻 🐱‍💻 Social Links:
    Facebook - / thenetninjauk
    Twitter - / thenetninjauk
    Instagram - / thenetninja

ความคิดเห็น • 145

  • @theebookkeeper
    @theebookkeeper ปีที่แล้ว +81

    for anyone having difficulties running the json-server command: Here is the solution:
    Run:
    npx json-server --watch data/db.json
    Happy coding :)

    • @reinoutko
      @reinoutko ปีที่แล้ว +2

      Thanks that worked, the line in the video gave me an error

    • @danielwarzecha2007
      @danielwarzecha2007 ปีที่แล้ว

      Thank you!

    • @razorX_09
      @razorX_09 11 หลายเดือนก่อน

      The man's a life saver!

    • @programmerhp7736
      @programmerhp7736 11 หลายเดือนก่อน

      thank you

    • @chip9417
      @chip9417 9 หลายเดือนก่อน

      legend

  • @tswtdt555
    @tswtdt555 3 ปีที่แล้ว +20

    Seriously, as everyone has already said, Thank you very much!! Please keep doing this!! You've helped a lot. I'm actually getting pretty good at front end development and feel confident getting into back end.

  • @CV-wo9hj
    @CV-wo9hj 6 หลายเดือนก่อน +16

    Awesome series thank you. With the latest json server "1.0.0-alpha.20", I had to modify db.json otherwise I kept getting a 404 not found. I had to add quotation marks around the ID numbers as follows {
    "jobs": [
    {
    "id": "1",
    "title": "Ninja UX Designer",
    "details": "lorem"
    },
    {
    "id": "2",
    "title": "Ninja Web Developer",
    "details": "lorem"
    },
    {
    "id": "3",
    "title": "Ninja Vue Developer",
    "details": "lorem"
    }
    ]
    }

    • @nathanrochas8449
      @nathanrochas8449 6 หลายเดือนก่อน

      Thank you I was digging the Internet searching for a fix

    • @AlberthAndrade
      @AlberthAndrade 6 หลายเดือนก่อน

      Thanks bro, why does it happen? We don't know... hahaha

    • @mlokish
      @mlokish 5 หลายเดือนก่อน

      Had the same issue, thanks for solution!

    • @who-1880
      @who-1880 4 หลายเดือนก่อน

      thanks!

    • @omar2006xxx
      @omar2006xxx 3 หลายเดือนก่อน

      Thanks! Same here.

  • @blakebedford-palmer6676
    @blakebedford-palmer6676 3 ปีที่แล้ว +5

    Love it! Maybe one thing overlooked, is even if you use a invalid job ID ( /jobs/6), JSON server returns 404 but sends an empty object, so when you do v-if="job" it's still true, even though this.job is just an empty object

  • @silenthill8312
    @silenthill8312 ปีที่แล้ว +2

    I gotta tell you
    You're a life saver
    Everytime i get stuck at something i always come here and miraculously almost every problem get solved

    • @NetNinja
      @NetNinja  ปีที่แล้ว

      Aha, glad I could help :) thanks for watching!

  • @Bemidbar
    @Bemidbar 2 ปีที่แล้ว +1

    You are a brilliant teacher! Thank you very much!

  • @softwareEngineerKunwar
    @softwareEngineerKunwar 3 ปีที่แล้ว +5

    Thank for tutorials, please bring more tutorials in vue 3 like crud api, crud more. There are very few tutorials in vue 3 and you tutorials are best among them. I hope you also use bootstap 4 or 5 for ui.

  • @tomvanbrabant3053
    @tomvanbrabant3053 3 ปีที่แล้ว +2

    Many thanks for these great tutorials!

  • @mauricemakesmovies
    @mauricemakesmovies ปีที่แล้ว +2

    You're a great teacher. Keep up the good work Shaun!

    • @NetNinja
      @NetNinja  ปีที่แล้ว +2

      Thanks Maurice, I appreciate that! :)

  • @hawarhekmat1174
    @hawarhekmat1174 3 ปีที่แล้ว +1

    thank you, you are teaching in best way ❤️

  • @qhphan5
    @qhphan5 3 ปีที่แล้ว +7

    For all those who are too lazy to navigate to the course files:
    {
    "jobs": [
    { "title": "Ninja UX Designer", "id": 1, "details": "lorem" },
    { "title": "Ninja Web Developer", "id": 2, "details": "lorem" },
    { "title": "Ninja Vue Developer", "id": 3, "details": "lorem" }
    ]
    }

  • @ankithap7624
    @ankithap7624 3 ปีที่แล้ว

    thank you for your awesome content shaun

  • @fredpourlesintimes
    @fredpourlesintimes 2 ปีที่แล้ว

    Interesting and proper way to work with data.
    Thanks :)

  • @diamondsky6605
    @diamondsky6605 2 ปีที่แล้ว

    I love your voice you're good for explaining the code
    Shout-out from France ❤️

  • @badreddinlabed530
    @badreddinlabed530 3 ปีที่แล้ว +1

    Thank u so much Ninja ❤ u are the best!

  • @RohitThakur-sj7en
    @RohitThakur-sj7en 3 ปีที่แล้ว +16

    I stopped continuing Vue and switched to React a few months ago. But, now I'm back, thanks to you. Love your tutorials :)

    • @mohdmahtab8991
      @mohdmahtab8991 3 ปีที่แล้ว +1

      React vs Vue which one best ?

    • @RohitThakur-sj7en
      @RohitThakur-sj7en 3 ปีที่แล้ว +9

      @@mohdmahtab8991 Both of them are great frameworks. But I would suggest going with Vue as it is a lot more beginner friendly.

    • @TheCodingOdyssey
      @TheCodingOdyssey 3 ปีที่แล้ว +5

      I've been working with React for over a year. I am thinking to start learning Vue as well. How different is it?

    • @mohdmahtab8991
      @mohdmahtab8991 3 ปีที่แล้ว +2

      @@RohitThakur-sj7en thankyou brother 🙂

    • @RohitThakur-sj7en
      @RohitThakur-sj7en 3 ปีที่แล้ว +6

      @@TheCodingOdyssey I would insist you to give it a try. Everything is far more convenient in Vue.

  • @BarbaraBezd
    @BarbaraBezd 4 หลายเดือนก่อน

    Thank you very much for your course! it's extremely helpful and easy to understand!

    • @NetNinja
      @NetNinja  4 หลายเดือนก่อน

      Glad it was helpful! :) thanks for watching

  • @robinbeaudru6892
    @robinbeaudru6892 2 ปีที่แล้ว +2

    Thank you, very useful tutorial series.
    I'm wondering, why don't you have to filter the results from the fetch with the id props? is JSON Server already configured for that? Cheers!

  • @Skaxarrat
    @Skaxarrat 2 ปีที่แล้ว +6

    Thanks for this incredible tutorials, Shaun.
    btw, one way to not getting an error is making the "job" variable an object:
    data() {
    return {
    job: {},
    }
    },

    • @dotunn
      @dotunn ปีที่แล้ว +1

      thanks so much, that was driving me crazy lol, i was wondering why it wasnt working

  • @user-cw4mm7ip4h
    @user-cw4mm7ip4h 2 ปีที่แล้ว +1

    Such an excellent video! Thank you!

    • @NetNinja
      @NetNinja  2 ปีที่แล้ว

      You're very welcome!

  • @learnsimple4592
    @learnsimple4592 3 ปีที่แล้ว +10

    Thanks Shaun. Best tutorial ever. Just wanted to know whether you are planning on a MEVN stack or a sass tutorial and which UI com potent library do you recommend for vue.

    • @NetNinja
      @NetNinja  3 ปีที่แล้ว +8

      Hey, I may do a full stack Vue project at some point but was thinking of using GraphQL. May also do a SASS refresh at some point too. I really like Vuetify for Vue 2, looking forward to it's new relase for v3 :)

    • @learnsimple4592
      @learnsimple4592 3 ปีที่แล้ว

      @@NetNinja As long as it is Vue fullstack (graphQL or MEVN). Count me in.

    • @hassanmiiro1030
      @hassanmiiro1030 3 ปีที่แล้ว

      @@learnsimple4592 @The Net Ninja me too.

    • @00el04
      @00el04 3 ปีที่แล้ว +1

      @@NetNinja subscribed for more future content :)

  • @kaleabwoldemariam4288
    @kaleabwoldemariam4288 2 หลายเดือนก่อน

    Thank you for the thorough tutorial.❤

    • @NetNinja
      @NetNinja  2 หลายเดือนก่อน

      Hope it was helpful! thanks for watching :)

  • @_isaac_muniz_
    @_isaac_muniz_ 2 ปีที่แล้ว +2

    i wasn't able to run json-server so i installed it globally with 'npm install -g json-server' and it worked fine

  • @mateuszfrydrych9822
    @mateuszfrydrych9822 2 ปีที่แล้ว +4

    A little hint: for chromium-based browsers (Chrome, Edge, I don't know about others) you can limit the network speed for the browser. This is done in the "Network" tab (where you have viewed the queries sent to the server) from the "Unlimited" option to one of the ready settings, eg "Fast 3G network" or "Slow 3G network" or any custom setting.
    Regards

    • @kajganamakedonska1846
      @kajganamakedonska1846 ปีที่แล้ว +1

      why would you do that?

    • @bakatoroi
      @bakatoroi 11 หลายเดือนก่อน +2

      @@kajganamakedonska1846 To better see what happens at 11:30. Also testing in general.

  • @zenmasterfu
    @zenmasterfu 2 ปีที่แล้ว +4

    If you wish to show the "results loading ..." pages add "--delay (time in ms)" to the json-server command. I use 500 ms..

  • @ramohacks
    @ramohacks 2 ปีที่แล้ว

    Is it a preference to using mounted vs created vs beforeMounted ?

  • @rezwansaki
    @rezwansaki 3 ปีที่แล้ว

    Thanks :)

  • @ccindy951357
    @ccindy951357 7 หลายเดือนก่อน

    謝謝!

  • @yaqubyusuf2834
    @yaqubyusuf2834 3 ปีที่แล้ว

    Thank you

  • @00el04
    @00el04 3 ปีที่แล้ว +1

    so would you rarely fetch JSON data on a local file server?

  • @ghostkillerbr9
    @ghostkillerbr9 10 หลายเดือนก่อน +1

    thankss :)

  • @Akosiyawin
    @Akosiyawin 2 ปีที่แล้ว

    Hi, from my experience you would fetch data in a created() life cycle hook, it's much better for handling get requests

  • @yadude101
    @yadude101 3 ปีที่แล้ว +1

    at 4:00 , aren't yarn🧶installs better for Macs? with npm, a lot of the time you have to do a sudo install, which isn't advisable

  • @MatichekYoutube
    @MatichekYoutube 2 ปีที่แล้ว

    Hi, can you create multiple fetch statements there?

  • @gilbertandsausage
    @gilbertandsausage ปีที่แล้ว +4

    After installing json-server it wouldn't let me use json-server in command line, to fix this I installed it globally adding the -g tag after "install" then installing it locally to the project. I'm not sure if anyone else has experienced this issue but if you are this is how you resolve that.

  • @lilmila4533
    @lilmila4533 ปีที่แล้ว +3

    is there a tutorial of yours which you use database instead of a json?

  • @3d_cube_3d95
    @3d_cube_3d95 2 ปีที่แล้ว +1

    How do I cancel my previous fetch request ? Let's say I was fetching a data on my project then while my page is still fetching I changed to another page route?

  • @rickycaron2177
    @rickycaron2177 3 ปีที่แล้ว +2

    Hello, I have a question.
    What if I want to use "job title" to search in the JSON array by the fetch function, rather than using "id"? Is there a way to do so?

    • @emil371
      @emil371 ปีที่แล้ว +1

      Did you find a way to do this?

  • @jesserigon
    @jesserigon 10 หลายเดือนก่อน +1

    why use mounted hook and not beforemount or something like that so you dont have to write all the conditionals?

  • @dikebambangsk4864
    @dikebambangsk4864 2 ปีที่แล้ว

    is it fetch automatic can call after install on package.json, not import the node-fetch

  • @angelosarnaoutis6391
    @angelosarnaoutis6391 3 ปีที่แล้ว +8

    If you want to test "loading jobs...", you can add a delay to the response of the json server. This can be done by adding to the json-server command the --delay or -d and the the number of milliseconds you want the response to be delayed.

    • @franklinsampaio9254
      @franklinsampaio9254 3 ปีที่แล้ว +4

      Or you can just press F12, go to network and change from 'online' to 'slow 3g'. With that you can test this too...

  • @marcmil4064
    @marcmil4064 5 หลายเดือนก่อน

    Awesome video!
    One suggestion though: We should hope that the company always has at least one open job, otherwise the length of the array will stay 0 and "Loading" will be shown forever ;)

  • @tomvanbrabant3053
    @tomvanbrabant3053 3 ปีที่แล้ว

    Why not pass the job as a prop to JobDetails? For production, would it be better performance because you don't fetch it twice? Thanks.

  • @ridl27
    @ridl27 3 ปีที่แล้ว

    ty.

  • @bryannsi
    @bryannsi 3 ปีที่แล้ว

    how setup vue auto-complete in vscode?

  • @mustafaerk3491
    @mustafaerk3491 3 ปีที่แล้ว

    If we got error UI will present still loading bc we didnt change jobs.length or job if we got error but btw it was great tutorial. Its not hard to handle that case . Thank you

  • @dayanavm
    @dayanavm 3 ปีที่แล้ว +3

    npx json-server --watch data/db.json = This command help me to watch file using json-server in windows.

    • @user-ki9gw8nl1d
      @user-ki9gw8nl1d 6 หลายเดือนก่อน

      doesn't work, that appear in my screen ; file:///C:/Users/aa/AppData/Roaming/npm/node_modules/json-server/lib/bin.js:4
      import { parseArgs } from 'node:util';
      ^^^^^^^^^
      SyntaxError: The requested module 'node:util' does not provide an export named 'parseArgs'
      at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
      at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
      at async Promise.all (index 0)
      at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
      at async loadESM (node:internal/process/esm_loader:88:5)
      at async handleMainPromise (node:internal/modules/run_main:61:12)

  • @Viralplace
    @Viralplace ปีที่แล้ว

    Finally you don't explain the lazy-loading route... what is the difference

  • @georgi_verstapen33
    @georgi_verstapen33 11 หลายเดือนก่อน +2

    If you face this issue "json-server : The term 'json-server' is not recognized as the name of a cmdlet, function, script file, or operable program"
    Simpli write: npx json-server --watch src/data/db.json --port 3000. This will solve the above error and will host the json-server on your desired port (in this example on port 3000)
    Hope this helped you, dear developer :)

  • @derekbressler9154
    @derekbressler9154 3 ปีที่แล้ว +2

    vue is the best!

  • @yusha790
    @yusha790 2 ปีที่แล้ว

    keep making vue vids please

  • @danielorkan5151
    @danielorkan5151 3 ปีที่แล้ว +4

    $ json-server -watch data/db.json (I got command not found: json-server)
    I'm using MacOS with npm (6.14.4)
    In order to solve this I had to uninstall json-server using:
    $ npm uninstall json-server
    and then install json-server globally using:
    $ npm install -g json-server

  • @chanhkunbin906
    @chanhkunbin906 2 ปีที่แล้ว

    i using axios and call api from MongoDB, however when i get the id from the job page it says detailJobs error 404 has format detailJobs/undefined

  • @trickytricks3071
    @trickytricks3071 2 ปีที่แล้ว

    how to get data from list without using loop?
    I am import array of data from api but i want to you use only one row,so please tell me how to get data using index number...
    I have tried list[0].title but it shows error

  • @derekbressler9154
    @derekbressler9154 3 ปีที่แล้ว

    vue is the best

  • @lilmila4533
    @lilmila4533 ปีที่แล้ว

    how can we fetch data from a created database server for vue.js?

  • @danielwarzecha2007
    @danielwarzecha2007 ปีที่แล้ว

    Note: at the 12 minute mark, if your getting a net::ERR_BLOCKED_BY_CLIENT error message....it is likely that it is your browser ad blocker! disable it, or use a different browser, this was the problem for me when using the brave browser, I just clicked the lion head and disabled it and it works fine

  • @chenqu773
    @chenqu773 3 ปีที่แล้ว +1

    I doun't knaow the origin of your accent. Bot it's very charming I reeely like it!

    • @NetNinja
      @NetNinja  3 ปีที่แล้ว +1

      Thank you! 😃 I'm from Manchester, UK!

    • @chenqu773
      @chenqu773 3 ปีที่แล้ว +1

      @@NetNinja Hoooray! Again, many thanks to your great tutorial !

  • @rommyrisyandi2863
    @rommyrisyandi2863 2 ปีที่แล้ว

    i got problem in section 5:26 and the problem is this : json-server : The term 'json-server' is not recognized as the name of a cmdlet, function, script file, or operable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1 is there anyone can help me?

  • @user-sr2fn5is8b
    @user-sr2fn5is8b 2 ปีที่แล้ว

    I undestand how make a list of items in json-server, but how to delete any item from my list using fetch request? how to address to exact id?

  • @dlysele
    @dlysele 3 ปีที่แล้ว +1

    Hi there, I am just learning Vue and I am creating a map app. I have already placed a geolocation script to output the latitude and longitude values on the DOM but I don't know how to refer the data back to the server, do you have an clue what I should do/look for? Thank you!

  • @creadigma360
    @creadigma360 2 ปีที่แล้ว

    Very helpful. I have fetched users with '/wp/v2/users' endpoint, but I can only get my own user data, I get a 401 error response when trying to get something like '/wp/v2/users/2'. How can I authenticate in order to get All Users data? I need to lists employees...
    I tried adding a header argument to the fetch function but it didn't work, I'm guessing It's because headers had already been sent, but I'm new to WP API REST, and to Vuejs, so I don't really know... I'm simply adding Vuejs for a couple of pages, as a script file from a CDN. I only find information about classic ajax so I don't know how to authenticate through API REST and Vuejs
    P.D. : I had already generated my application password, just don't know where/how to place credentials. Running WP 5.9.3

  • @tona17yo
    @tona17yo 2 ปีที่แล้ว

    Pero de esta forma haces 2 peticiones, en la primera ya tienes todo, por qué no almacenarlo en vuex y desplegar la data necesaria por medio de su id?

  • @jimos9878
    @jimos9878 9 หลายเดือนก่อน

    The same way 'jobs' is not null because it's just an empty array (value), couldn't we set 'job' property to {} instead of null? So it would be an empty object and not null. Or is {} still a null value?

  • @michalsejak
    @michalsejak 2 ปีที่แล้ว

    Why does this not cause the CORS policy problem? Can anyone please explain that to me?

  • @BenjaminGSlade
    @BenjaminGSlade 5 หลายเดือนก่อน

    "fetch data", does that mean fetch data from a database to memory? or to/from/ memory from/to the screen?

  • @user-rm4nv1ql6t
    @user-rm4nv1ql6t 2 ปีที่แล้ว

    Thank you ! by japanese(日本人)

  • @Ln6Ec
    @Ln6Ec 5 หลายเดือนก่อน

    The mounted fetch request within JobDetails isn't working for me for some reason... if I have the (res => res.json()) portion in it, there's an unexpected character error that comes up. If I switch res.json() to res.text() that error goes away, but I get another error saying the requested localhost:3000/jobs/1 isn't found. Can anyone help me please?

    • @miloszl0
      @miloszl0 4 หลายเดือนก่อน

      add quotation marks to the ID in json file, like this:
      {
      "jobs": [
      {
      "id": "1",
      "title": "Ninja UX Designer",
      "details": "lorem"
      },
      {
      "id": "2",
      "title": "Ninja Web Developer",
      "details": "lorem"
      },
      {
      "id": "3",
      "title": "Ninja Vue Developer",
      "details": "lorem"
      }
      ]
      }

  • @adilizm704
    @adilizm704 3 ปีที่แล้ว

    i can't get the data when I pass the id as a parameter to the API how you did that ?? I think you miss a part there ?? any idea

  • @0jhivag
    @0jhivag ปีที่แล้ว

    Great,but how i do this in composition api,how i get the id?

    • @pt_trainer9244
      @pt_trainer9244 10 หลายเดือนก่อน

      Use props or vue router and pass the Id with the params parameter

  • @khouloudcherrat1060
    @khouloudcherrat1060 2 ปีที่แล้ว +1

    at 15:58 the problem can be fixed quickly if we set job : {}.

  • @g2rocky231
    @g2rocky231 3 ปีที่แล้ว +1

    Hello sir,
    I want to learn app development.
    But I don't know which one to prefer "react-native" or "flutter". I know react js very well and also flutter a bit. Can you prefer which one is better.

  • @gokulpisharody3155
    @gokulpisharody3155 3 ปีที่แล้ว

    Shaun what about angular course? Any plan to create one.?

  • @jamols09
    @jamols09 3 ปีที่แล้ว +1

    I just think its better to cover on axios than fetch

    • @anthonygoodjobs4544
      @anthonygoodjobs4544 3 ปีที่แล้ว

      Not really, it's much better to use the native Fetch for these type of cases.

  • @sauravjain6135
    @sauravjain6135 3 ปีที่แล้ว +6

    Noobs favourite: Angular
    Pro favourite: React
    Hackers favourite: Vue

  • @sudhanwabokade1285
    @sudhanwabokade1285 หลายเดือนก่อน

    11:00

  • @alielzahaby3315
    @alielzahaby3315 8 หลายเดือนก่อน +1

    {
    "jobs": [
    { "title": "Ninja UX Designer", "id": 1, "details": "lorem" },
    { "title": "Ninja Web Developer", "id": 2, "details": "lorem" },
    { "title": "Ninja Vue Developer", "id": 3, "details": "lorem" }
    ]
    }
    np ;)

  • @SUBZER0GREEN
    @SUBZER0GREEN 10 หลายเดือนก่อน

    9:00

  • @antoniofuller2331
    @antoniofuller2331 2 ปีที่แล้ว

    Hmmm

  • @shubhang2877
    @shubhang2877 3 ปีที่แล้ว

    What is your dog's name?

    • @NetNinja
      @NetNinja  3 ปีที่แล้ว +4

      I don't have one, but if I did I would call it Yoshi :)

    • @shubhang2877
      @shubhang2877 3 ปีที่แล้ว +2

      Wait then who's the cutie on your github pfp?

  • @paycation3966
    @paycation3966 2 ปีที่แล้ว

    Is this tutor British?

    • @NetNinja
      @NetNinja  2 ปีที่แล้ว +2

      Hey yes, I am from Manchester, England :)

  • @ivansanczewski6648
    @ivansanczewski6648 ปีที่แล้ว

    I bought this tutorial and follow this part and it worked fine for me, until I had to use a json file with Pinia… I can GET mock data from my file and populate an array, but when it comes to POST new data I keep on receiving this error: "POST localhost:3000/borrowedBooks 500 (Internal Server Error)"
    Any help would be highly appreciated!