nickbasile / comments-demo Goto Github PK
View Code? Open in Web Editor NEWA Vue.js, Laravel, and Tailwind CSS comments components
A Vue.js, Laravel, and Tailwind CSS comments components
Good afternoon, Nick Basile.
Thank you for your blog , i had learnt a lot . I found a small bug on the first post of Building A Comments System With Vue.js, Laravel, and Tailwind CSS Part I.
Here is your original code:
//Template
<div>
<div>
<h2>Comments</h2>
</div>
<textarea v-model="data.body"
placeholder="Add a comment"
class="border">
</textarea>
<div>
<button @click="saveComment">Save</button>
<button>Cancel</button>
</div>
</div>
//Script
saveComment() {
let newComment = {
id: this.comments[this.comments.length - 1].id + 1,
body: this.data.body,
edited: false,
created_at: new Date().toLocaleString(),
author: {
id: this.user.id,
name: this.user.name,
}
}
this.comments.push(newComment);
this.data.body = '';
}
We should change the data
to comments
. if we do not do that ,we will get an error and the browser will show nothing.
I had changed my code like below:
// template
<div>
<div>
<h2>Comments</h2>
</div>
<textarea v-model="comments.body"
placeholder="Add a comment"
class="border">
</textarea>
<div>
<button @click="saveComment">Save</button>
<button>Cancel</button>
</div>
</div>
// script
saveComment() {
let newComment = {
id: this.comments[this.comments.length - 1].id + 1,
body: this.comments.body,
edited: false,
created_at: new Date().toLocaleString(),
author: {
id: this.user.id,
name: this.user.name,
}
}
this.comments.push(newComment);
this.comments.body = '';
},
And also I am using the latest laravel 5.7 , we don't have asserts folder in my resources directory.
Thank you very much , wish this can help others .
Hello @nickbasile Thanks for your awesome post.
I want to use diffForHumans()
on created_at
column. How can I do that on the collection? This is how comments are fetched.
$comments = Comment::with('author')
->orderByDesc('id')
->get();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.