You can simply use ave in base R:
with(DT, ave(v1, c(0, cumsum(v1)[-length(v1)]), FUN = seq_along))
# 1 2 3 4 1 2 3
Or if you want in dplyr also you can use the lag() and with that just create groups and you can assign row numbers in each and every group:
DT %>% group_by(gr = lag(cumsum(v1), default = 0)) %>% mutate(ID = row_number())
If you are beginner and want to know more about R programming, then do check out the R programming tutorial.