All Projects → runkids → vue2-timeago

runkids / vue2-timeago

Licence: MIT license
🙌 A vue component used to format date with time ago statement. 💬

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language
Vue
7211 projects

Projects that are alternatives of or similar to vue2-timeago

Nutui
京东风格的移动端 Vue2、Vue3 组件库 (A Vue.js UI Toolkit for Mobile Web)
Stars: ✭ 3,870 (+4992.11%)
Mutual labels:  vue-components, vue3, vite
codemirror-editor-vue3
CodeMirror component for Vue3
Stars: ✭ 22 (-71.05%)
Mutual labels:  vue-components, vue3, vite
vui-vc-next
Vue 3 with Vite Playground - Mobile web UI components - (vue3+vite2).
Stars: ✭ 15 (-80.26%)
Mutual labels:  vue-components, vue3, vite
Vue3 News
🔥 Find the latest breaking Vue3、Vue CLI 3+ & Vite News. (2021)
Stars: ✭ 2,416 (+3078.95%)
Mutual labels:  vue-components, vue3, vite
vue3-manjaro-ui
网页版Manjaro。A simulation webpage for Manjaro Linux(KDE Plasma).
Stars: ✭ 109 (+43.42%)
Mutual labels:  vue3, vite
vuestic-ui
Free and Open Source UI Library for Vue 3 🤘
Stars: ✭ 1,501 (+1875%)
Mutual labels:  vue-components, vue3
tov-template
vite + vue3 + ts 开箱即用现代开发模板
Stars: ✭ 251 (+230.26%)
Mutual labels:  vue3, vite
vue3-tutorial
Vue3.2、Vite、setup、echarts、composition API
Stars: ✭ 302 (+297.37%)
Mutual labels:  vue3, vite
vitailse
Opinionated Vite starter template with TailwindCSS
Stars: ✭ 95 (+25%)
Mutual labels:  vue3, vite
vite-vue3-tailwind
Boilerplate at vue 3 whit firebase, vue notus, typesctip, vite, tailwind
Stars: ✭ 21 (-72.37%)
Mutual labels:  vue3, vite
portfolio
simple portfolio use vue3 and vite inspired by wrongakram
Stars: ✭ 22 (-71.05%)
Mutual labels:  vue3, vite
vue-vben-admin
A modern vue admin. It is based on Vue3, vite and TypeScript. It's fast!
Stars: ✭ 12,169 (+15911.84%)
Mutual labels:  vue3, vite
vue3-element-admin
🎉 基于 vite2 + vue3 + element-plus 的后台管理系统vue3-element-admin;使用vue-cli可以切换webpack分支
Stars: ✭ 79 (+3.95%)
Mutual labels:  vue3, vite
fearless
A dashboard scaffolding based on Vue.js 3.x & TypeScript created by Vite.
Stars: ✭ 1,156 (+1421.05%)
Mutual labels:  vue3, vite
v-intl
Add i18n to your awesome Vue 3 app 🔉
Stars: ✭ 13 (-82.89%)
Mutual labels:  vue-components, vue3
nuxt3-tailwind
nuxt3 boilerplate with tailwind and dynamic routes.
Stars: ✭ 52 (-31.58%)
Mutual labels:  vue3, vite
vite-svg
Use SVG files as Vue components with Vite
Stars: ✭ 98 (+28.95%)
Mutual labels:  vue3, vite
vite-primevue-starter
VUE 3 Starter project for using primevue 3 with Vite 2 - Pages, Layouts, Validation
Stars: ✭ 37 (-51.32%)
Mutual labels:  vue3, vite
admin-antd-vue
Vue3.x + Ant Design Admin template (vite/webpack)
Stars: ✭ 111 (+46.05%)
Mutual labels:  vue3, vite
vitesome
A simple opinionated Vue3 Starter Template with Vite.js
Stars: ✭ 124 (+63.16%)
Mutual labels:  vue3, vite

vue2-timeago

vue2 npm npm npm

vue2-timeago V2

🔥 NEW vue2-timeago for Vue 3

  • Localization supported
  • Show tooltip
  • Auto refresh time
  • When time refresh call a customizable function
  • Formats a date/timestamp to:
    • just now
    • 5m
    • 3h
    • 2 days ago
    • 2017-08-03
  • Rules:
    • less than 1 minute , show just now
    • 1 minute ~ 1 hour , show ** minutes ago
    • 1 hour ~ 1 day , show ** hours ago
    • 1 day ~ 1 month( 31 days ) , show ** days ago
    • more than 1 month( 31 days ) , show yyyy-mm-dd hh:mm
FOR 1.X PLEASE GO TO THE 1.x BRANCH

Navigation

Live Demo

Edit vue2_timeago_demo

Local Demo

yarn
yarn serve

Installation

Get from npm / yarn:

npm i vue2-timeago@2.0.6
yarn add vue2-timeago@2.0.6

or just include vue2-timeago.umd.min.js to your view like

<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/vue2-timeago.umd.min.js'></script>

Usage

Use this inside your app:

import { TimeAgo } from 'vue2-timeago'

export default {
  name: 'app',
  components: {
    TimeAgo,
  }
}
With Default CSS
import 'vue2-timeago/dist/vue2-timeago.css'

or just include vue2-timeago.css

HTML
<time-ago :refresh="60" :datetime="new Date(2018, 7, 4, 0, 24, 0)" locale="zh_TW" tooltip></time-ago>

Examples

1. locale

Default locale is en, and the library supports en and zh_TW.

<time-ago locale="en"></time-ago> 
<time-ago :locale="locale"></time-ago> use v-bind
export default {
  ...
  data(){
    return{
      locale:"zh_TW",
    }
  },
  ...
2. datetime
<time-ago datetime="2018-08-03 15:47:00"></time-ago> 
<time-ago :datetime="new Date(2018, 7, 4, 0, 24, 0)"></time-ago> use v-bind
<time-ago :datetime="1533286641826"></time-ago> timestamp
  • Note. Don't bind with new Date() when you use refresh property. Because every time refresh will get a new date value.

    <time-ago :datetime="new Date(2018, 7, 4, 0, 24, 0)"></time-ago>  --> OK
    <time-ago refresh :datetime="new Date()"></time-ago> --> not OK

    If you want use new Date() , just remove datetime property.

    <time-ago refresh></time-ago>
3. refresh
<time-ago refresh></time-ago> Boolean , default refresh time 60/s
<time-ago :refresh="3600"></time-ago> bind value with a number
<time-ago :refresh="1"></time-ago> Refresh time 1 second
4. tooltip

  • Base on v-tooltip, you can use placement attribute that are allowed in v-tooltip.
<time-ago tooltip></time-ago> Show tooltip 
<time-ago :tooltip="false"></time-ago> Disabled tooltip
5. tooltip options
  • Default options:
{
  placement: 'top',
  content: {datetime string}
}
  • Custom options
<time-ago tooltip :tooltip-options="tooltipOptions"/>
data () {
  return {
    tooltipOptions: {
      placement: 'bottom',
    }
  }
}
6. long
<time-ago :datetime="datetime"></time-ago> show : 2d
<time-ago :datetime="datetime" long></time-ago> show : 2 days ago
7. vue2-timeago event

You can do something when time refresh every time

<time-ago :refresh="1" :locale="locale" @update="timeRefresh" />

Parameters example:

methods: {
  timeRefresh({ timeago, nowString, timestamp }) {
    console.log(timeago) // 51m
    console.log(nowString) // 2021-01-21 10:55
    console.log(timestamp) // Thu Jan 21 2021 10:55:18 GMT+0800 (台北標準時間)
  }
}
8. native event
<time-ago @click="todo"><time-ago/>
<time-ago @mouseover="todo"><time-ago/>

Props

Property Type Default Description
datetime Date, String, Number new Date() The datetime to be formatted.
locale String en message language
refresh Boolean, Number false The period to update the component, in seconds. When true it will be 60s. Also you can bind a number.
long Boolean false Show long string with time message . ex. 3h -> 3 hours age
tooltip Boolean false Show tooltip.
tooltip-options Object { placement: 'top', content: #datetime string } tooltip options

Event

Property Description
update After timer refreshed will trigger this event

Nuxt (global registration)

To install in nuxt run

npm i vue2-timeago

In nuxt.config.js add

  plugins: [
    { src: '~/plugins/vue2-timeago' }
  ],

In plugins/vue2-timeago.js type:

import Vue from 'vue';
import { TimeAgo } from 'vue2-timeago';

import 'vue2-timeago/dist/vue2-timeago.css';

Vue.component('time-ago', TimeAgo);

Then in components use as:

<time-ago :datetime="new Date()" tooltip/>

Contributions

locale translations: The component needs more locale translations. You can Open an issue to write the locale translations, or submit a pull request. See example here.

locale support list :

  • English ( en )
  • 繁體中文 ( zh_TW )
  • 简体中文 ( zh_CN )
  • 日本語 ( jp )
  • Korean ( ko )
  • Portugal(Brazil) ( pt_BR )
  • Spain ( es )
  • Arabia ( ar )
  • French ( fr )
  • Polish ( pl )
  • Turkish ( tr )
  • Indonesian ( id )
  • Romanian ( ro )
  • Russian ( ru )
  • Germany ( de )
  • Ukrainian ( uk )
  • Bulgarian ( bg )
  • Swedish ( se )
  • Dutch / Netherlands ( nl )
  • Hebrew ( he )
  • Thai ( th )

Thanks for help:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].