angular.js - 前后端分离的点赞功能样式问题
我想大声告诉你
我想大声告诉你 2017-05-15 16:53:56
0
2
619

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

我想大声告诉你
我想大声告诉你

reply all(2)
Ty80

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.

伊谢尔伦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!