Home  >  Q&A  >  body text

angular.js - 前后端分离的点赞功能样式问题

我是用vue写的前端页面。点赞和取消点赞api我已经写好了,只需要向api传输文章的id就可以,还有一个判断你是否已经点赞的api,已经文章也是由api获取
现在遇到的问题是,我想在样式上做改变,就是初始化加载页面的时候,就判断好这篇文章你是否点过赞,然后样式是点赞了的样式。但是文章是由v-repeat生成的(类似ng-repeat),我在文章中加入过滤器当前文章是否点过赞,在Ajax的回调改写dom,但由于异步的问题,改写的dom被vue的渲染给无效了。有什么好的办法吗?

我想大声告诉你我想大声告诉你2737 days ago639

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 16:55:56

    I have done something similar, but using angularjs
    It’s the same as before, but I thought of a way for the likes class, you can see if it suits you:
    For example, nice is a Boolean value in the lists (returned by the server) array. If the judgment point has not been clicked, use this value to cycle through the like button class when loading for the first time
    Then add an ng-click to the like button to send http. After the sending is successful, change the Boolean value of list.nice, and then change the state. To determine the position of list.nice, pass an $index to the method that encapsulates http. Alright.
    The rewriting of the dom you mentioned does not actually change the value of the two-way binding. It is still traditional jquery thinking. Changing the binding value should be a more appropriate method. You can try it.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-15 16:55:56

    You should use vue’s own methods to manage styles instead of manually changing the dom

    reply
    0
  • Cancelreply