vuejs2 - dynamic variable combining a double value + filter -


i have following case:

<bl-card :subtitle="card.beforechanged + ' ' + (card.changed | formatdate)" />

the subtitle needs set combining 2 strings. card.beforechanged contains "last changed to:" string, card.changed variable contains datetimestring. via de formatdate() datetimestring gets formatted readable date.

subtitle returns: "last changed to: 2069882880".

the question: possible combine 2 strings 1 of them get's formatted via filter property in 1 go?

you should use computer property that.

vue.filter('formatdate', function (value) {      return moment(value).fromnow()  })    vue.component('todo', {   		computed: {      	formatedtext: function () {        	return `${this.text} - ${vue.filter('formatdate')(this.date)}`      	}    	},   		props: ['text', 'date'],      template: '<li>{{ formatedtext }}</li>'  });    var demo = new vue({      el: '#demo',      data: {        todos: [          {text:'testing', date: new date()},          {text:'old text', date: moment().subtract(7, 'days')}        ]      }  })
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script>  <div id="demo" v-cloak>      <p v-if="!todos.length">no todos @ moment.</p>      <ul v-else>          <todo v-for="t in todos" :text=t.text :date=t.date></todo>      </ul>  </div>


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -