D
D
denis_lunochkin2017-10-19 23:44:57
css
denis_lunochkin, 2017-10-19 23:44:57

What is the correct way to write a computed property?

Hello, I've run into this problem. You need to write a calculated property in vue.js that will take the width of the block, then do the calculation (width / 2 * (-1)) and apply the result to the margin-left property of the block. I know that it will sound strange, but I know how to solve this question on Jquery and pure js, here is an example on Jquery:

jQuery(document).ready(function($) {
  var width = $('.ucp').width();
  $('.ucp').css('margin-left', width / 2 * (-1) );
});

The problem is that I want to try to change the width reactively, but I don't know how to write all this correctly. I'm new to vue, if it's not difficult, describe how you can use vue (v-bind: style) to reactively calculate changing values. I can imagine how it should look like, but I'm still confused.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Kazakov, 2017-10-20
@walovari

Here is an example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question